@Juha:
Using UtfUpperCase in Utf8CompareText just hides the problem.
Geepster seems to expect that comparing 'apple' with '_apple' must give the same result as comparing 'APPLE' with '_APPLE' using a sase sensitive algorithm.
While on Windows, with a "Western" locale this is the case, It cannot be guaranteed to be so on all platforms on all locales, even in a plain fpc program.
Both CompareStr, Utf8CompareStr and Utf8CompareText use CompareMemRange, and this will give different results in these cases, since it will compare '_' against either 'A' or 'a'.
If you want case-insensistve results use a case-insensitive alogorithm.
Even then the result may be different on different platforms, thus making sorting things (and I guess a binary tree is sorted?) complicated.
So, whichever way we go, as long as we use CompareMemRange, the result may not be what a human would expect, since we just compare byte values, and have no intrinsic knowledge about language sorting orders.
Another approach would be to query the underlying OS (like AnsiCompareStr does), but even then I think Geepster has a flaw in his reasoning, and his problem will not be resolved.
However we can do so by using WideCompare functions (LazUtf8 does not override these for the widestringmanager), and at least on Windows this then works as Geepster expects it to be (but IMO still by shear luck).
I'm unaware of the WideCompare functions implementation on other platforms (Linux, OSX), so I can't comment on that at all.
(I do know that we then need cwstring on *nix, or fpwidestring (slower but consistent across all platforms)).
Bart