I need to globally replace certain words in a text file and because
I need to process it a byte at a time initially...I'm inputting
processed list of bytes into the global replace function "lchg"
(and others) like this.
(lbytes_to_fl Cleaned_txt_pth
(lchg "fl ow" "flow"
(fltr2
(fltr1
(fl_to_lbytes Txt_pth)))))
The other filters seem ok but this one is slow (most likely my
algorithm/general approach :)) and any help to
speed things up would be much appreciated.
(de lchg (Sfrom Sto Lbytes)
(make
(let
(X 0
B NIL
Lfrom (mapcar char (chop Sfrom))
Lto (mapcar char (chop Sto))
First_from_ch (car Lfrom)
Len_from-1 (- (length Lfrom) 1)
Len_lbytes (length Lbytes) )
(until (<= (length Lbytes) X)
(inc 'X)
(setq B (get Lbytes X))
(if (= B First_from_ch)
(prog
(if (= (slice Lbytes X (+ X Len_from-1)) Lfrom)
(prog
(for MatchB Lto
(link MatchB) )
(inc 'X Len_from-1) )
(link B) ) )
(link B) ) ) ) ) )
(de slice (Lst I K) (head (inc (- K I)) (nth Lst I)) ) #99
Here's "lchg" in action...
: (setq L (chop "ab fl ow flow fl ow yz"))
-> ("a" "b" " " "f" "l" " " "o" "w" " " "f" "l" "o" "w" " " "f" "l" " " "o"
"w" " " "y" "z")
: (pack (mapcar char (lchg "fl ow" "flow" (mapcar char L))))
-> "ab flow flow flow yz"