UPD: Switch to using LazUtils for UTF8ToSys and SysToUTF8 in doublecmd_common package, now that we require Lazarus 1.0.

This commit is contained in:
cobines 2013-08-17 19:16:15 +00:00
commit 3dec27c8a8
2 changed files with 5 additions and 93 deletions

View file

@ -49,11 +49,6 @@ const
faInvalidAttributes: TFileAttrs = TFileAttrs(-1);
CopyAttributesOptionCopyAll = [caoCopyAttributes, caoCopyTime, caoCopyOwnership];
// From Lazarus LCL.
// Once switched to Lazarus 1.0 we can use package LazUtils instead and remove those.
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
{en
Is file a directory
@param(iAttr File attributes)
@ -180,20 +175,20 @@ function mbLoadLibrary(const Name: UTF8String): TLibHandle;
implementation
{$IF DEFINED(MSWINDOWS)}
uses
Windows, JwaWinNetWk;
{$IF DEFINED(MSWINDOWS)}
Windows, JwaWinNetWk,
{$ENDIF}
{$IF DEFINED(UNIX)}
{$IF DEFINED(BSD)}
{$DEFINE FPC_USE_LIBC}
{$ENDIF}
uses
{$IF (NOT DEFINED(FPC_USE_LIBC)) OR (DEFINED(BSD) AND NOT DEFINED(DARWIN))}
SysCall,
{$ENDIF}
BaseUnix, Unix, dl, DCStrUtils;
BaseUnix, Unix, dl,
{$ENDIF}
DCStrUtils, LazUTF8;
{$IFDEF UNIX}
function SetModeReadOnly(mode: TMode; ReadOnly: Boolean): TMode;
@ -239,89 +234,6 @@ end;
{$ENDIF}
{$ENDIF}
//////////
// From Lazarus, remove once switched to Lazarus 1.0, use LazUtils instead.
var
FNeedRTLAnsi: boolean = false;
FNeedRTLAnsiValid: boolean = false;
function NeedRTLAnsi: boolean;
{$IFDEF WinCE}
// CP_UTF8 is missing in the windows unit of the Windows CE RTL
const
CP_UTF8 = 65001;
{$ENDIF}
{$IFNDEF Windows}
var
Lang: String;
i: LongInt;
Encoding: String;
{$ENDIF}
begin
if FNeedRTLAnsiValid then
exit(FNeedRTLAnsi);
{$IFDEF Windows}
FNeedRTLAnsi:=GetACP<>CP_UTF8;
{$ELSE}
FNeedRTLAnsi:=false;
Lang := SysUtils.GetEnvironmentVariable('LC_ALL');
if lang = '' then
begin
Lang := SysUtils.GetEnvironmentVariable('LC_MESSAGES');
if Lang = '' 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;
{$ENDIF}
FNeedRTLAnsiValid:=true;
Result:=FNeedRTLAnsi;
end;
procedure SetNeedRTLAnsi(NewValue: boolean);
begin
FNeedRTLAnsi:=NewValue;
FNeedRTLAnsiValid:=true;
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;
end;
function SysToUTF8(const s: string): string;
begin
if NeedRTLAnsi and (not IsASCII(s)) then
begin
Result:=AnsiToUTF8(s);
{$ifdef FPC_HAS_CPSTRING}
// prevent UTF8 codepage appear in the strings - we don't need codepage
// conversion magic in LCL code
SetCodePage(RawByteString(Result), StringCodePage(s), False);
{$endif}
end
else
Result:=s;
end;
//////////
(*Is Directory*)
function FPS_ISDIR(iAttr: TFileAttrs) : Boolean; inline;

View file

@ -22,7 +22,7 @@ implementation
uses
Forms, Controls, Dialogs, LCLProc, LCLStrConsts, syncobjs,
uDebug, uLng, uGlobs, uDCVersion, DCOSUtils;
uDebug, uLng, uGlobs, uDCVersion, DCOSUtils, LazUTF8;
type
THandleException = class