FileUtil: inline NeedRTLAnsi, SetNeedRTLAnsi, UTF8ToSys ans UTF8ToAnsi to use their LazuUtf8 counterparts.

git-svn-id: trunk@41280 -
This commit is contained in:
bart 2013-05-19 11:43:06 +00:00
parent 8357d5ad1f
commit da816b1721
4 changed files with 12 additions and 64 deletions

View File

@ -17,39 +17,26 @@
*****************************************************************************
}
var
FNeedRTLAnsi: boolean = false;
FNeedRTLAnsiValid: boolean = false;
function NeedRTLAnsi: boolean;
begin
Result := LazUtf8.NeedRTLAnsi;
end;
procedure SetNeedRTLAnsi(NewValue: boolean);
begin
FNeedRTLAnsi:=NewValue;
FNeedRTLAnsiValid:=true;
LazUtf8.SetNeedRTLAnsi(NewValue);
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;
begin
if NeedRTLAnsi and (not IsASCII(s)) then
Result := UTF8ToAnsi(s)
else
Result := s;
Result := LazUtf8.UTF8ToSys(s);
end;
function SysToUTF8(const s: string): string;
begin
if NeedRTLAnsi and (not IsASCII(s)) then
Result:=AnsiToUTF8(s)
else
Result:=s;
Result := LazUtf8.SysToUTF8(s);
end;
{$IFDEF darwin}

View File

@ -205,10 +205,10 @@ function GetTempFilename(const Directory, Prefix: string): string;
// AnsiToUTF8 and UTF8ToAnsi need a widestring manager under Linux, BSD, MacOSX
// but normally these OS use UTF-8 as system encoding so the widestringmanager
// is not needed.
function NeedRTLAnsi: boolean;// true if system encoding is not UTF-8
procedure SetNeedRTLAnsi(NewValue: boolean);
function UTF8ToSys(const s: string): string;// as UTF8ToAnsi but more independent of widestringmanager
function SysToUTF8(const s: string): string;// as AnsiToUTF8 but more independent of widestringmanager
function NeedRTLAnsi: boolean; inline;// true if system encoding is not UTF-8
procedure SetNeedRTLAnsi(NewValue: boolean); inline;
function UTF8ToSys(const s: string): string; inline;// as UTF8ToAnsi 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 UTF8ToConsole(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)

View File

@ -302,33 +302,6 @@ begin
Result:=FilenameIsUnixAbsolute(TheFilename);
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)
begin

View File

@ -139,19 +139,7 @@ begin
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)
var