// globally modifies unicode text within an active file. Colud be edited to work with a selection range.
function SearchReplace(MemoString: TRichMemo;
SearchText, ReplaceText: widestring): Boolean;
var startpos, startrun: longint;
opt: TSearchOptions;
begin
with MemoString do // ** needs editing for a selection range **
begin
opt:= []; // no options set
SelStart:= 0;
Lines.BeginUpdate; // suspends visual update
while MemoString.Search(SearchText, SelStart, GetTextLen - SelStart, opt, startpos, startrun) do
begin
SelStart:= startpos;
SelLength:= startrun;
SelText:= ReplaceText;
SelStart:= startpos + 1;
end;
Lines.EndUpdate; // installs visual update
end;
end;
//The following is an application of SearchReplace. It globally exchanges Syriac Western vowels with Eastern vowels.
//There are additional codes that have to be developed to exhaustively manage the replacements ... but this is a starter.
//Done is assigned for future needs but is not currently implemented to do anything.
var
fs: TFileStream;
Done: boolean;
begin
(*
.... do stuff ... like DiskName:= OpenDialog1.Filename; {DiskName is global string} {PageMemo is RichMemo}
*)
try fs:= TFileStream.Create(Utf8ToAnsi(DiskName), fmOpenRead or fmShareDenyNone);
PageMemo.LoadRichText(fs);
Done:= SearchReplace(PageMemo, UnicodeToUTF8(1840), UnicodeToUTF8(1842)); // ptx (ah) <dot above with dot below>
Done:= SearchReplace(PageMemo, UnicodeToUTF8(1843), UnicodeToUTF8(1845)); // zqp (au) <skewed double-dots above>
Done:= SearchReplace(PageMemo, UnicodeToUTF8(1846), UnicodeToUTF8(1848)); // rbs (eh) <two flat dots below>
Done:= SearchReplace(PageMemo, UnicodeToUTF8(1853), UnicodeToUTF8(1855)); // esa (oo) <single dot above>
Done:= SearchReplace(PageMemo, UnicodeToUTF8(1850), UnicodeToUTF8(1849)); // xbs (ih, no yud) <skewed double-dots below>
Done:= SearchReplace(PageMemo, UnicodeToUTF8(1864), UnicodeToUTF8(1863)); // silent oblique above
Done:= SearchReplace(PageMemo, UnicodeToUTF8(1849)+UnicodeToUTF8(1821), // zlm (ih & yud) <single dot below yud>
UnicodeToUTF8(1821)+UnicodeToUTF8(1852));
PageMemo.Hint:= DiskName; // OpenDialog1.Filename;
finally
fs.Free;
end;
end;