I agree. Ive seen this. And I traced it to functions, and some dll stuff.
Really!? I'm actually a little pissed off. As a coder of some 25+ years, Ive base a lot of my trust on simple ideas, like the ASCII code.
I understand I don't know "the world", but, this just is weird.
Notice that CompareStr gives the same results as Utf8CompareStr:
Utf8CompareStr(APPLE,_APPLE) = -30
Utf8CompareStr(apple,_apple) = 2
CompareStr(APPLE,_APPLE) = -30
CompareStr(apple,_apple) = 2
This is because Ord('A') < Ord('_') < Ord('a');
(CompareMemRange returns this)
CompareText compares uppercase values, while Utf8CompareText compares lowercase values.
Default AnsicompareText/AnsiCompareStr (as in a pure console app under windows, no LazUtf8 involvement) ask Windows for the result:
function Win32AnsiCompareStr(const S1, S2: string): PtrInt;
begin
result:=CompareStringA(LOCALE_USER_DEFAULT,0,pchar(s1),length(s1),
pchar(s2),length(s2))-2;
end;
If your binary search relies on the fact that comparing 'apple' vs '_apple' must give a positive value always (case independant) then using AnsiCompareText (which maps to Utf8CompareText in Lazarus) should do just that.
If your compariosn must always be a positive value, but the the keywords itself have different meaning depending on case (as in C), then you basically are screwed, since AnsiCompareStr's result will always depend on the widestringmanager and therefore the results can differ across platforms and locales.
Bart