mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 09:19:22 +02:00
lazutils: fix GetFormatSettingsUTF8, make it public
git-svn-id: trunk@52479 -
This commit is contained in:
parent
2a7afe821b
commit
b08c38cba0
@ -62,6 +62,9 @@ function UTF8ToWinCP(const s: string): string; {$ifdef WinCe}inline;{$endif}
|
|||||||
|
|
||||||
function ParamStrUTF8(Param: Integer): string;
|
function ParamStrUTF8(Param: Integer): string;
|
||||||
|
|
||||||
|
procedure GetFormatSettingsUTF8;
|
||||||
|
procedure GetLocaleFormatSettingsUTF8(LCID: Integer; var aFormatSettings: TFormatSettings);
|
||||||
|
|
||||||
function GetEnvironmentStringUTF8(Index: Integer): string;
|
function GetEnvironmentStringUTF8(Index: Integer): string;
|
||||||
function GetEnvironmentVariableUTF8(const EnvVar: string): String;
|
function GetEnvironmentVariableUTF8(const EnvVar: string): String;
|
||||||
|
|
||||||
|
@ -364,46 +364,31 @@ end;
|
|||||||
|
|
||||||
function GetLocaleCharUTF8(aLocaleID, aLCType: Longint; Def: Char): Char;
|
function GetLocaleCharUTF8(aLocaleID, aLCType: Longint; Def: Char): Char;
|
||||||
var
|
var
|
||||||
Buf: array[0..3] of WChar; // sdate allows 4 chars.
|
Buf: array[0..3] of WideChar; // sdate allows 4 chars (3+ending #0)
|
||||||
GLI: LongInt;
|
GLI, I: LongInt;
|
||||||
|
WRes: WideChar;
|
||||||
begin
|
begin
|
||||||
//Use Widestring Api so it works on WinCE as well
|
//Use Widestring Api so it works on WinCE as well
|
||||||
GLI := GetLocaleInfoW(aLocaleID, aLCType, Buf, sizeof(buf));
|
GLI := GetLocaleInfoW(aLocaleID, aLCType, Buf, Length(Buf)); // GLI is char count with the ending #0 char
|
||||||
if (GLI > 0) and (ord(Buf[0])<128) then
|
if GLI > 2 then
|
||||||
Result := Buf[0]
|
begin // more than 2 chars -> try to find first non-space character
|
||||||
else begin
|
for I := 0 to GLI-2 do
|
||||||
Result := Def;
|
begin
|
||||||
{
|
WRes := Buf[I];
|
||||||
case Buf[0] of
|
case Buf[I] of
|
||||||
#$C2:
|
#32, #$00A0, #$2002, #$2003, #$2009, #$202F: begin end;// go over spaces
|
||||||
case Buf[1] of
|
else
|
||||||
#$A0: Result:=' '; // non breakable space
|
Break; // stop at non-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
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
}
|
end else
|
||||||
if (GLI = 1) then begin
|
if GLI = 2 then // 1 char
|
||||||
case Buf[0] of
|
WRes := Buf[0]
|
||||||
|
else
|
||||||
|
WRes := Def;
|
||||||
|
|
||||||
|
case WRes of
|
||||||
|
#0..#127: Result := WRes;// ASCII - OK
|
||||||
#$00A0: Result := ' '; // non breakable space
|
#$00A0: Result := ' '; // non breakable space
|
||||||
#$00B7: Result := '.'; // middle stop
|
#$00B7: Result := '.'; // middle stop
|
||||||
#$02D9: Result := ''''; // dot above, italian handwriting
|
#$02D9: Result := ''''; // dot above, italian handwriting
|
||||||
@ -428,12 +413,12 @@ begin
|
|||||||
E2 80 94 -> 2014
|
E2 80 94 -> 2014
|
||||||
E2 8E 96 -> 2396
|
E2 8E 96 -> 2396
|
||||||
}
|
}
|
||||||
|
else // unicode character -> we need default ASCII char
|
||||||
|
Result := Def;
|
||||||
end; //case
|
end; //case
|
||||||
end; //GLI = 1
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure GetFormatSettingsUTF8(LCID: Integer; var aFormatSettings: TFormatSettings);
|
procedure GetLocaleFormatSettingsUTF8(LCID: Integer; var aFormatSettings: TFormatSettings);
|
||||||
var
|
var
|
||||||
HF : Shortstring;
|
HF : Shortstring;
|
||||||
LID : Windows.LCID;
|
LID : Windows.LCID;
|
||||||
@ -480,6 +465,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure GetFormatSettingsUTF8;
|
||||||
|
begin
|
||||||
|
{$ifndef wince}
|
||||||
|
GetLocaleFormatSettingsUTF8(GetThreadLocale, FormatSettings);
|
||||||
|
{$else}
|
||||||
|
GetLocaleFormatSettingsUTF8(GetUserDefaultLCID, FormatSettings);
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
|
|
||||||
function UTF8StrCompAnsiString(S1, S2: PChar): PtrInt;
|
function UTF8StrCompAnsiString(S1, S2: PChar): PtrInt;
|
||||||
begin
|
begin
|
||||||
Result:=UTF8CompareStrP(S1,S2);
|
Result:=UTF8CompareStrP(S1,S2);
|
||||||
@ -541,11 +535,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$IFDEF UTF8_RTL}
|
{$IFDEF UTF8_RTL}
|
||||||
{$ifndef wince}
|
GetFormatSettingsUTF8;
|
||||||
GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
|
|
||||||
{$else}
|
|
||||||
GetFormatSettingsUTF8(GetUserDefaultLCID ,FormatSettings);
|
|
||||||
{$endif}
|
|
||||||
widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
|
widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
|
||||||
widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
|
widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
|
||||||
widestringmanager.CompareStrAnsiStringProc:=@UTF8CompareStr;
|
widestringmanager.CompareStrAnsiStringProc:=@UTF8CompareStr;
|
||||||
|
Loading…
Reference in New Issue
Block a user