lazutils: fix GetFormatSettingsUTF8, make it public

git-svn-id: trunk@52479 -
This commit is contained in:
ondrej 2016-06-12 05:57:58 +00:00
parent 2a7afe821b
commit b08c38cba0
2 changed files with 61 additions and 68 deletions

View File

@ -62,6 +62,9 @@ function UTF8ToWinCP(const s: string): string; {$ifdef WinCe}inline;{$endif}
function ParamStrUTF8(Param: Integer): string;
procedure GetFormatSettingsUTF8;
procedure GetLocaleFormatSettingsUTF8(LCID: Integer; var aFormatSettings: TFormatSettings);
function GetEnvironmentStringUTF8(Index: Integer): string;
function GetEnvironmentVariableUTF8(const EnvVar: string): String;

View File

@ -364,46 +364,31 @@ end;
function GetLocaleCharUTF8(aLocaleID, aLCType: Longint; Def: Char): Char;
var
Buf: array[0..3] of WChar; // sdate allows 4 chars.
GLI: LongInt;
Buf: array[0..3] of WideChar; // sdate allows 4 chars (3+ending #0)
GLI, I: LongInt;
WRes: WideChar;
begin
//Use Widestring Api so it works on WinCE as well
GLI := GetLocaleInfoW(aLocaleID, aLCType, Buf, sizeof(buf));
if (GLI > 0) and (ord(Buf[0])<128) then
Result := Buf[0]
else begin
Result := Def;
{
case Buf[0] of
#$C2:
case Buf[1] of
#$A0: Result:=' '; // non breakable space
#$B7: Result:='.'; // middle stop
end;
#$CB:
if Buf[1]=#$99 then Result:=''''; // dot above, italian handwriting
#$D9:
case Buf[1] of
#$AB: Result:=','; // arabic decimal separator, persian thousand separator
#$AC: Result:=''''; // arabic thousand separator
end;
#$E2:
case Buf[1] of
#$80:
case Buf[2] of
#$82, // long space
#$83, // long space
#$89, // thin space
#$AF: // narrow non breakable space
Result := ' ';
#$94: Result := '-'; // persian decimal mark
end;
#$8E: if Buf[2]=#$96 then Result := ''''; // codepoint 9110 decimal separator
GLI := GetLocaleInfoW(aLocaleID, aLCType, Buf, Length(Buf)); // GLI is char count with the ending #0 char
if GLI > 2 then
begin // more than 2 chars -> try to find first non-space character
for I := 0 to GLI-2 do
begin
WRes := Buf[I];
case Buf[I] of
#32, #$00A0, #$2002, #$2003, #$2009, #$202F: begin end;// go over spaces
else
Break; // stop at non-space
end;
end;
}
if (GLI = 1) then begin
case Buf[0] of
end else
if GLI = 2 then // 1 char
WRes := Buf[0]
else
WRes := Def;
case WRes of
#0..#127: Result := WRes;// ASCII - OK
#$00A0: Result := ' '; // non breakable space
#$00B7: Result := '.'; // middle stop
#$02D9: Result := ''''; // dot above, italian handwriting
@ -428,12 +413,12 @@ begin
E2 80 94 -> 2014
E2 8E 96 -> 2396
}
else // unicode character -> we need default ASCII char
Result := Def;
end; //case
end; //GLI = 1
end;
end;
procedure GetFormatSettingsUTF8(LCID: Integer; var aFormatSettings: TFormatSettings);
procedure GetLocaleFormatSettingsUTF8(LCID: Integer; var aFormatSettings: TFormatSettings);
var
HF : Shortstring;
LID : Windows.LCID;
@ -480,6 +465,15 @@ begin
end;
end;
procedure GetFormatSettingsUTF8;
begin
{$ifndef wince}
GetLocaleFormatSettingsUTF8(GetThreadLocale, FormatSettings);
{$else}
GetLocaleFormatSettingsUTF8(GetUserDefaultLCID, FormatSettings);
{$endif}
end;
function UTF8StrCompAnsiString(S1, S2: PChar): PtrInt;
begin
Result:=UTF8CompareStrP(S1,S2);
@ -541,11 +535,7 @@ begin
end;
end;
{$IFDEF UTF8_RTL}
{$ifndef wince}
GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
{$else}
GetFormatSettingsUTF8(GetUserDefaultLCID ,FormatSettings);
{$endif}
GetFormatSettingsUTF8;
widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
widestringmanager.CompareStrAnsiStringProc:=@UTF8CompareStr;