mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 16:00:26 +02:00
FileUtil: inline NeedRTLAnsi, SetNeedRTLAnsi, UTF8ToSys ans UTF8ToAnsi to use their LazuUtf8 counterparts.
git-svn-id: trunk@41280 -
This commit is contained in:
parent
8357d5ad1f
commit
da816b1721
@ -17,39 +17,26 @@
|
|||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
}
|
}
|
||||||
|
|
||||||
var
|
|
||||||
FNeedRTLAnsi: boolean = false;
|
|
||||||
FNeedRTLAnsiValid: boolean = false;
|
|
||||||
|
|
||||||
|
function NeedRTLAnsi: boolean;
|
||||||
|
begin
|
||||||
|
Result := LazUtf8.NeedRTLAnsi;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure SetNeedRTLAnsi(NewValue: boolean);
|
procedure SetNeedRTLAnsi(NewValue: boolean);
|
||||||
begin
|
begin
|
||||||
FNeedRTLAnsi:=NewValue;
|
LazUtf8.SetNeedRTLAnsi(NewValue);
|
||||||
FNeedRTLAnsiValid:=true;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function IsASCII(const s: string): boolean; inline;
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
for i:=1 to length(s) do if ord(s[i])>127 then exit(false);
|
|
||||||
Result:=true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function UTF8ToSys(const s: string): string;
|
function UTF8ToSys(const s: string): string;
|
||||||
begin
|
begin
|
||||||
if NeedRTLAnsi and (not IsASCII(s)) then
|
Result := LazUtf8.UTF8ToSys(s);
|
||||||
Result := UTF8ToAnsi(s)
|
|
||||||
else
|
|
||||||
Result := s;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SysToUTF8(const s: string): string;
|
function SysToUTF8(const s: string): string;
|
||||||
begin
|
begin
|
||||||
if NeedRTLAnsi and (not IsASCII(s)) then
|
Result := LazUtf8.SysToUTF8(s);
|
||||||
Result:=AnsiToUTF8(s)
|
|
||||||
else
|
|
||||||
Result:=s;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$IFDEF darwin}
|
{$IFDEF darwin}
|
||||||
|
@ -205,10 +205,10 @@ function GetTempFilename(const Directory, Prefix: string): string;
|
|||||||
// AnsiToUTF8 and UTF8ToAnsi need a widestring manager under Linux, BSD, MacOSX
|
// AnsiToUTF8 and UTF8ToAnsi need a widestring manager under Linux, BSD, MacOSX
|
||||||
// but normally these OS use UTF-8 as system encoding so the widestringmanager
|
// but normally these OS use UTF-8 as system encoding so the widestringmanager
|
||||||
// is not needed.
|
// is not needed.
|
||||||
function NeedRTLAnsi: boolean;// true if system encoding is not UTF-8
|
function NeedRTLAnsi: boolean; inline;// true if system encoding is not UTF-8
|
||||||
procedure SetNeedRTLAnsi(NewValue: boolean);
|
procedure SetNeedRTLAnsi(NewValue: boolean); inline;
|
||||||
function UTF8ToSys(const s: string): string;// as UTF8ToAnsi but more independent of widestringmanager
|
function UTF8ToSys(const s: string): string; inline;// as UTF8ToAnsi but more independent of widestringmanager
|
||||||
function SysToUTF8(const s: string): string;// as AnsiToUTF8 but more independent of widestringmanager
|
function SysToUTF8(const s: string): string; inline;// as AnsiToUTF8 but more independent of widestringmanager
|
||||||
function ConsoleToUTF8(const s: string): string;// converts OEM encoded string to UTF8 (used with some Windows specific functions)
|
function ConsoleToUTF8(const s: string): string;// converts OEM encoded string to UTF8 (used with some Windows specific functions)
|
||||||
function UTF8ToConsole(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
|
function UTF8ToConsole(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
|
||||||
|
|
||||||
|
@ -302,33 +302,6 @@ begin
|
|||||||
Result:=FilenameIsUnixAbsolute(TheFilename);
|
Result:=FilenameIsUnixAbsolute(TheFilename);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function NeedRTLAnsi: boolean;
|
|
||||||
var
|
|
||||||
Lang: String;
|
|
||||||
i: LongInt;
|
|
||||||
Encoding: String;
|
|
||||||
begin
|
|
||||||
if FNeedRTLAnsiValid then
|
|
||||||
exit(FNeedRTLAnsi);
|
|
||||||
FNeedRTLAnsi:=false;
|
|
||||||
Lang := SysUtils.GetEnvironmentVariable('LC_ALL');
|
|
||||||
if Length(lang) = 0 then
|
|
||||||
begin
|
|
||||||
Lang := SysUtils.GetEnvironmentVariable('LC_MESSAGES');
|
|
||||||
if Length(Lang) = 0 then
|
|
||||||
begin
|
|
||||||
Lang := SysUtils.GetEnvironmentVariable('LANG');
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
i:=System.Pos('.',Lang);
|
|
||||||
if (i>0) then begin
|
|
||||||
Encoding:=copy(Lang,i+1,length(Lang)-i);
|
|
||||||
FNeedRTLAnsi:=(SysUtils.CompareText(Encoding,'UTF-8')<>0)
|
|
||||||
and (SysUtils.CompareText(Encoding,'UTF8')<>0);
|
|
||||||
end;
|
|
||||||
FNeedRTLAnsiValid:=true;
|
|
||||||
Result:=FNeedRTLAnsi;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function ConsoleToUTF8(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
|
function ConsoleToUTF8(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
|
||||||
begin
|
begin
|
||||||
|
@ -139,19 +139,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function NeedRTLAnsi: boolean;
|
|
||||||
{$IFDEF WinCE}
|
|
||||||
// CP_UTF8 is missing in the windows unit of the Windows CE RTL
|
|
||||||
const
|
|
||||||
CP_UTF8 = 65001;
|
|
||||||
{$ENDIF}
|
|
||||||
begin
|
|
||||||
if FNeedRTLAnsiValid then
|
|
||||||
exit(FNeedRTLAnsi);
|
|
||||||
FNeedRTLAnsi:=GetACP<>CP_UTF8;
|
|
||||||
FNeedRTLAnsiValid:=true;
|
|
||||||
Result:=FNeedRTLAnsi;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function ConsoleToUTF8(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
|
function ConsoleToUTF8(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user