when searching backwards in unicode strings, the PosText function does not yield the expected results.
Sample code:
Code: Select all
program TestMadStrings;
{$APPTYPE CONSOLE}
uses
madStrings;
function IfThen(ACond: boolean; ATrue, AFalse: string): string;
begin
if ACond then Result := ATrue
else Result := AFalse;
end;
procedure Test(sub: string; text: string; expected: integer; ignoreCase: boolean); overload;
var
Result: integer;
begin
Write('Test"', sub, '"'#9'in "',text, '"'#9'(', IfThen(ignoreCase, 'no case', ' case'), ') ... ');
if IgnoreCase then Result := PosText(sub, text, maxInt, 1)
else Result := PosStr(sub, text, maxInt, 1);
if Result = expected then
WriteLn(#9'OK.'#9'(Position is ', result, ')')
else
WriteLn(#9'Failed!'#9'(Position is ',result,', should be ',expected,'!)');
end;
procedure Test(sub: string; text: string; expected: integer); overload;
begin
Test(sub, text, expected, false);
Test(sub, text, expected, true);
WriteLn;
end;
begin
Test('34a', '1234b aa 567', 0);
Test('12', '1234b aa 567', 1);
Test('34b', '1234b aa 567', 3);
Test('aa', '1234baa5678', 6);
Test('aa', '1234baa 567', 6);
Test('b aa','1234b aa567', 5);
Test('aa', '1234b aa 567', 7);
ReadLn;
end.
Code: Select all
Test"34a" in "1234b aa 567" ( case) ... OK. (Position is 0)
Test"34a" in "1234b aa 567" (no case) ... OK. (Position is 0)
Test"12" in "1234b aa 567" ( case) ... OK. (Position is 1)
Test"12" in "1234b aa 567" (no case) ... OK. (Position is 1)
Test"34b" in "1234b aa 567" ( case) ... OK. (Position is 3)
Test"34b" in "1234b aa 567" (no case) ... OK. (Position is 3)
Test"aa" in "1234baa5678" ( case) ... OK. (Position is 6)
Test"aa" in "1234baa5678" (no case) ... Failed! (Position is 0, should be 6!)
Test"aa" in "1234baa 567" ( case) ... OK. (Position is 6)
Test"aa" in "1234baa 567" (no case) ... Failed! (Position is 0, should be 6!)
Test"b aa" in "1234b aa567" ( case) ... OK. (Position is 5)
Test"b aa" in "1234b aa567" (no case) ... OK. (Position is 5)
Test"aa" in "1234b aa 567" ( case) ... OK. (Position is 7)
Test"aa" in "1234b aa 567" (no case) ... Failed! (Position is 6, should be 7!)
Andre