diff --git a/packages/rtl-objpas/src/inc/strutils.pp b/packages/rtl-objpas/src/inc/strutils.pp index 828979b473..7f2dcf47fb 100644 --- a/packages/rtl-objpas/src/inc/strutils.pp +++ b/packages/rtl-objpas/src/inc/strutils.pp @@ -440,7 +440,7 @@ begin AddMatch(i+1); //Only first match ? if not aMatchAll then break; - inc(i,DeltaJumpTable2[0]); + inc(i,DeltaJumpTable2[0]+1); end else begin i:=i + Max(DeltaJumpTable1[ord(s[i])],DeltaJumpTable2[j]); end; @@ -592,7 +592,7 @@ begin AddMatch(i+1); //Only first match ? if not aMatchAll then break; - inc(i,DeltaJumpTable2[0]); + inc(i,DeltaJumpTable2[0]+1); end else begin i:=i + Max(DeltaJumpTable1[Ord(lCaseArray[Ord(s[i])])],DeltaJumpTable2[j]); end; diff --git a/tests/webtbs/tw39709.pp b/tests/webtbs/tw39709.pp new file mode 100644 index 0000000000..401f42abd5 --- /dev/null +++ b/tests/webtbs/tw39709.pp @@ -0,0 +1,26 @@ +{$mode delphi} +uses + SysUtils, StrUtils; + + procedure Test(const s, find, repl, expect: 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)); + if StrUtils.StringReplace(s, find, repl, flags, algo)<>expect then + halt(1); + end; + +var + algo: TStringReplaceAlgorithm; + +begin + for algo in TStringReplaceAlgorithm do + begin + writeln(algo); + Test('This works', 'works', 'only works', 'This only works', [rfReplaceAll], algo); + Test('Hello World', 'hello', 'goodbye', 'goodbye World', [rfReplaceAll, rfIgnoreCase], algo); + Test('ababab', 'a', 'z', 'zbzbzb', [rfReplaceAll], algo); + Test('Nani wo nasu tame umareta?', 'a', '-', 'N-ni wo n-su t-me um-ret-?', [rfReplaceAll], algo); + writeln; + end; +end. diff --git a/tests/webtbs/tw39885.pp b/tests/webtbs/tw39885.pp new file mode 100644 index 0000000000..96de7dc166 --- /dev/null +++ b/tests/webtbs/tw39885.pp @@ -0,0 +1,25 @@ +uses + strutils; +Var + matches: SizeIntArray; + i : Longint; + +begin + FindMatchesBoyerMooreCaseSensitive('a x b x c', 'x', matches, {matchAll}true); // never returns + if matches[0]<>3 then + halt(1); + if matches[1]<>7 then + halt(1); + FindMatchesBoyerMooreCaseSensitive('a xx b xx c', 'xx', matches, {matchAll}true); // never returns + if matches[0]<>3 then + halt(1); + if matches[1]<>8 then + halt(1); + FindMatchesBoyerMooreCaseSensitive('a xy b xy c', 'xy', matches, {matchAll}true); // ok + if matches[0]<>3 then + halt(1); + if matches[1]<>8 then + halt(1); + writeln('ok'); +end. +