lazutils: merged some duplicates

git-svn-id: trunk@35424 -
This commit is contained in:
mattias 2012-02-17 15:22:24 +00:00
parent 587a1ef0fd
commit 4fdb9ca1a2
4 changed files with 9 additions and 54 deletions

View File

@ -17,15 +17,9 @@
*****************************************************************************
}
var
FNeedRTLAnsi: boolean = false;
FNeedRTLAnsiValid: boolean = false;
procedure SetNeedRTLAnsi(NewValue: boolean);
begin
FNeedRTLAnsi:=NewValue;
FNeedRTLAnsiValid:=true;
lazutf8.SetNeedRTLAnsi(NewValue);
end;
function IsASCII(const s: string): boolean; inline;
@ -38,18 +32,12 @@ 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:=SysToUTF8(s);
end;
{$IFDEF darwin}

View File

@ -185,10 +185,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

@ -269,31 +269,8 @@ begin
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;
Result:=lazutf8.NeedRTLAnsi;
end;
function ConsoleToUTF8(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
@ -306,7 +283,6 @@ begin
Result := UTF8ToSys(s);
end;
function FileExistsUTF8(const Filename: string): boolean;
begin
Result:=SysUtils.FileExists(UTF8ToSys(Filename));

View File

@ -117,17 +117,8 @@ 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;
Result:=LazUTF8.NeedRTLAnsi;
end;
function ConsoleToUTF8(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)