tw39709.pp 927 B

1234567891011121314151617181920212223242526
  1. {$mode delphi}
  2. uses
  3. SysUtils, StrUtils;
  4. procedure Test(const s, find, repl, expect: string; flags: TReplaceFlags; algo: TStringReplaceAlgorithm);
  5. begin
  6. write((s + ',').PadRight(27), ' ', find.PadRight(5), ' -> ', (repl + IfThen(rfIgnoreCase in flags, ' [I]') + ':').PadRight(12), ' ');
  7. writeln(StrUtils.StringReplace(s, find, repl, flags, algo));
  8. if StrUtils.StringReplace(s, find, repl, flags, algo)<>expect then
  9. halt(1);
  10. end;
  11. var
  12. algo: TStringReplaceAlgorithm;
  13. begin
  14. for algo in TStringReplaceAlgorithm do
  15. begin
  16. writeln(algo);
  17. Test('This works', 'works', 'only works', 'This only works', [rfReplaceAll], algo);
  18. Test('Hello World', 'hello', 'goodbye', 'goodbye World', [rfReplaceAll, rfIgnoreCase], algo);
  19. Test('ababab', 'a', 'z', 'zbzbzb', [rfReplaceAll], algo);
  20. Test('Nani wo nasu tame umareta?', 'a', '-', 'N-ni wo n-su t-me um-ret-?', [rfReplaceAll], algo);
  21. writeln;
  22. end;
  23. end.