Paul Ishenin schrieb:
A general function
function Pos(SubStr: T1; Str: T2): integer;
should return the character index of SubStr in Str, i.e. Str[i] should
definitely be the begin of SubStr within Str.
Just think of Pos() as it only compares bytes.
Ah, that may be correct for the old (ASCII/Ansi) model. Thanks for the
reminder :-)
AnsiPos() should care
about encoding too. As I remember AnsiPos() has AnsiString arguments
instead of RawByteString and therefore the conversion will be made
before the byte compare.
AnsiPos *was* designed for dealing with MBCS encodings, but in Unicode
Delphi the implementation changed to UnicodeString arguments, the "Ansi"
names only have been retained for compatibility with existing code.
Thus AnsiPos *now* only accepts UnicodeStrings, with obviously wrong
results when called with (automatically converted) AnsiStrings :-(
There exists an AnsiStrings unit, with another AnsiPos function, which
accepts an AnsiString. Unfortunately I couldn't make it work right now,
dunno why, and it only accepts native (CP_ACP) AnsiStrings - no solution
for UTF-8 strings :-(
DoDi
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel