diff --git a/components/lazutils/fileutil.inc b/components/lazutils/fileutil.inc index ae90cd8e65..f1a30c0ddf 100644 --- a/components/lazutils/fileutil.inc +++ b/components/lazutils/fileutil.inc @@ -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} diff --git a/components/lazutils/fileutil.pas b/components/lazutils/fileutil.pas index 2882badbbc..844767bda3 100644 --- a/components/lazutils/fileutil.pas +++ b/components/lazutils/fileutil.pas @@ -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) diff --git a/components/lazutils/unixfileutil.inc b/components/lazutils/unixfileutil.inc index 0332f33bea..49c782dc4e 100644 --- a/components/lazutils/unixfileutil.inc +++ b/components/lazutils/unixfileutil.inc @@ -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)); diff --git a/components/lazutils/winfileutil.inc b/components/lazutils/winfileutil.inc index fce05ca79f..b1d672aeb0 100644 --- a/components/lazutils/winfileutil.inc +++ b/components/lazutils/winfileutil.inc @@ -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)