Problem with PosText

delphi package - madRes, madTools, madStrings, ...

Problem with PosText

Postby a-s-z » Tue Sep 15, 2009 11:40 am

Hello,

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.


Running the program compiled with Delphi 2009 yields the following output:

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!)


Regards,
Andre
a-s-z
 
Posts: 12
Joined: Tue Sep 15, 2009 11:34 am

Postby madshi » Tue Sep 15, 2009 5:38 pm

Thanks for the report!

It seems that I already fixed this. At least I can't reproduce the problem anymore with the latest madCollection version, which I've uploaded just a couple of minutes ago:

http://madshi.net/madCollection.exe (2.5.11.1)
madshi
Site Admin
 
Posts: 9339
Joined: Sun Mar 21, 2004 5:25 pm

Postby a-s-z » Wed Sep 16, 2009 1:25 pm

Thanks, works like a charm now!

Greets,
Andre
a-s-z
 
Posts: 12
Joined: Tue Sep 15, 2009 11:34 am


Return to madBasic

Who is online

Users browsing this forum: No registered users and 1 guest

cron