How to compare case-insensitive text on OSX Yosemite

I am trying to compare two lines in OSX in case insensitive mode using AnsiSameText. This works well, but in OSX Yosemite it is strange if OSX's “preferred language” is set to Dutch (“System Preferences” → “Language and Region” → “Preferred Languages”, → “Dutch Dutch”).

In the following code example, I expect it to print only "the same". But I get "the same, different, different."

program Project2; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; begin if AnsiSameText('abcde', 'ABCDE') then // Same WriteLn('Same') else WriteLn('Different'); if AnsiSameText('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') then // different WriteLn('Same') else WriteLn('Different'); if AnsiSameText('i', 'I') then // different WriteLn('Same') else WriteLn('Different'); end. 

What is the correct way to compare case insensitive texts?

I am using Delphi XE7.

+5
source share
1 answer

Delphi initializes the UTF8CompareLocale with the value returned from CFLocaleCopyCurrent. UTF8CompareLocale is used internally by AnsiSameText for locale parameters that are used for case insensitive comparisons. But then OSX Yosemite believes that “I” and “i” are different if OSX is set to Dutch.

Call SetUTF8CompareLocale('en_US'); in the Dutch system fixes the problem without the need to fix Delphi blocks.

0
source

Source: https://habr.com/ru/post/1207019/


All Articles