News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: How text editors replace function works  (Read 3237 times)

Jandazekon

  • Full Member
  • ***
  • Posts: 130
    • View Profile
How text editors replace function works
« on: April 04, 2014, 03:30:34 pm »
Step 1:         ORIGINAL
A
B
C
D
E
F
G



Step 2:         CHANGING A INTO B
B
B
C
D
E
F
G



Step 3:         CHANGING B INTO F (both a and b is changed into f)
F
F
C
D
E
F
G



Step 4:         CHANGING C INTO E
F
F
E
D
E
F
G



Step 5:         CHANGING E INTO B (both c and e is changed into b)
F
F
B
D
B
F
G

FAST6191

  • Hero Member
  • *****
  • Posts: 2610
    • View Profile
Re: How text editors replace function works
« Reply #1 on: April 04, 2014, 05:14:13 pm »
I do not follow.

Are you after a general discussion of search algorithms/techniques, a way to program a tool so as to handle it (possibly from a ROM hacking perspective) or something like a batch script to do what you describe there?

For the former that is probably basic programming, a basic means to do it (even if you have to check every character one by one it is probably not going to be too slow for a modern PC to do it) should be available in just about every programming language worth a damn.
You probably also want to read up on regular expressions.

Programming a tool.
What was covered before works. Here though you are going to have to filter it through tables and input checking of some form. I am not sure what there is for some of the hex editors out there, if text editors would have covered the last one then hex editors are good for this.

For the batch file thing you probably want the wonder combo of grep, sed and awk.
http://matt.might.net/articles/sculpting-text/

Jandazekon

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: How text editors replace function works
« Reply #2 on: April 04, 2014, 05:21:54 pm »
Original:
id 0 = A
id 1 = B
id 2 = C
id 3 = D
id 4 = E
id 5 = F
id 6 = G



Changing A into B:
id 0 = B <-
id 1 = B
id 2 = C
id 3 = D
id 4 = E
id 5 = F
id 6 = G



Changing B into F:
id 0 = B
id 1 = F <-
id 2 = C
id 3 = D
id 4 = E
id 5 = F
id 6 = G

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3507
    • View Profile
    • Aeon Genesis
Re: How text editors replace function works
« Reply #3 on: April 04, 2014, 06:01:09 pm »
You wot, mate?

But seriously, I'm not entirely sure what you're trying to accomplish by posting this. These sorts of data replacement concepts are, like, remedial computers for technophobes stuff.

Jandazekon

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: How text editors replace function works
« Reply #4 on: April 05, 2014, 03:41:56 am »
Is there a text editor which knows what letters was changed to what.
And know their original names so not merge with them with other letters which has the same name.

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: How text editors replace function works
« Reply #5 on: April 05, 2014, 04:56:15 am »
No, because most people would just add a step using a temporary replacement symbol.
we are in a horrible and deadly danger

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: How text editors replace function works
« Reply #6 on: April 05, 2014, 05:14:32 am »
Or for bigger replacements, they just use a lookup table and do just one pass on the data.

Jandazekon

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: How text editors replace function works
« Reply #7 on: April 05, 2014, 05:43:17 am »
Or for bigger replacements, they just use a lookup table and do just one pass on the data.
A word search table?

FAST6191

  • Hero Member
  • *****
  • Posts: 2610
    • View Profile
Re: How text editors replace function works
« Reply #8 on: April 05, 2014, 06:15:05 am »
No.

The simple search and replace method involves starting at the top (or the cursor I guess) and checking every single character one by one, incrementing the compare function until you reach the end of the file. This is simple to do but not terribly quick. When your machine is screaming along at however many gigahertz though it tends not to matter so much.

The better, though slightly more memory intensive, method is to generate a list of every character in the document and note the locations. If you then know say the character b is at 0x35,0xed and 0xf0 then you can simply change the values at those locations if the program needs to change the character b (far quicker). Typically though programs will regenerate the table after every change/every function call making your desire to have the characters retain knowledge of their former state kind of hard. I guess you could alter the source to do such a thing (or have a disable updates and force redraw/regenerate option, be warned that adding new or removing characters/spaces/whatever would break things very fast). As BRPXQZME said though everybody that has to do this for anything will tend to add another stage and change the character to another previously unused one (#@[]{}.... the list goes on, if you are really hard pressed you can also use long runs of multiple characters that will also not turn up in the rest of your document).

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: How text editors replace function works
« Reply #9 on: April 05, 2014, 06:29:37 am »
Single pass infinite length needle replacer:
Code: [Select]
var matchTreePos=matchTreeRoot;
var outBuff:String="";
for(var i:uint=0;i<inBuff.length;++i) {
var readChar=inBuff[i];

var nextTreePos=matchTreePos.lut[readChar];
if(!nextTreePos) {
outBuff+=matchTreePos.replacement;
matchTreePos=matchTreeRoot;
} else {
matchTreePos=nextTreePos;
}
}