StrUtils.StringReplace(sraBoyerMoore) freezes
...(probably with eating all RAM, but I don’t want to check) on these examples, apart from the first. I didn't find a pattern (not that I was looking), but this behaviour looks easy to achieve with 1-character matches or with rfIgnoreCase
.
uses
SysUtils, StrUtils;
procedure Test(const s, find, repl: string; flags: TReplaceFlags; algo: TStringReplaceAlgorithm);
begin
write((s + ',').PadRight(27), ' ', find.PadRight(5), ' -> ', (repl + IfThen(rfIgnoreCase in flags, ' [I]') + ':').PadRight(12), ' ');
writeln(StrUtils.StringReplace(s, find, repl, flags, algo));
end;
var
algo: TStringReplaceAlgorithm;
begin
for algo in TStringReplaceAlgorithm do
begin
writeln(algo);
Test('This works', 'works', 'only works', [rfReplaceAll], algo);
Test('Hello World', 'hello', 'goodbye', [rfReplaceAll, rfIgnoreCase], algo);
Test('ababab', 'a', 'z', [rfReplaceAll], algo);
Test('Nani wo nasu tame umareta?', 'a', '-', [rfReplaceAll], algo);
writeln;
end;
end.
sraDefault
This works, works -> only works: This only works
Hello World, hello -> goodbye [I]: goodbye World
ababab, a -> z: zbzbzb
Nani wo nasu tame umareta?, a -> -: N-ni wo n-su t-me um-ret-?
sraManySmall
This works, works -> only works: This only works
Hello World, hello -> goodbye [I]: goodbye World
ababab, a -> z: zbzbzb
Nani wo nasu tame umareta?, a -> -: N-ni wo n-su t-me um-ret-?
sraBoyerMoore
This works, works -> only works: This only works
Hello World, hello -> goodbye [I]: <DEATH>
Edited by Rika