unit LConv; {This unit is to be inserted into LCL} {$mode objfpc}{$H+} //As iconv is Linux command, there is no sense in Windows {$IFDEF MSWindows} {$DEFINE WINDOWS} {$ENDIF} {$IFDEF WINDOWS} {$WARNINI Windows/Wine/ReactOS locale conversion is not fully supported yet. Sorry.} {$ENDIF} {$IFDEF UNIX} {$IFNDEF NOLIBC} {$DEFINE UNIXLibc} {$ENDIF} {$ENDIF} interface uses SysUtils,classes{$IFDEF UNIXLibc},libc{$ENDIF}{$IFDEF UNIX},unix{$ENDIF}; function CPConvert(const s,from,toC:string):string; function GetDefaultCodepage:string; implementation var GotCodepage:boolean=false; Codepage:string='ANSI'; function GetDefaultCodepage:string; var Lang:string; i:integer; s:string; begin if GotCodepage then begin Result:=Codepage;exit;end; {$ifndef UNIXLibc} Result:='ANSI'; Lang:=GetEnvironmentVariable('LANG'); i:=pos('.',Lang); if (i>0)and(i<=length(Lang)) then Result:=copy(Lang,i+1,length(Lang)-i); {$ELSE} Result:=nl_langinfo(CODESET); {$ENDIF} //Check parameters for i:=1 to ParamCount do begin s:=ParamStr(i); if s='--charset=' then Result:=copy(s,pos('=',s),length(s)); end; Codepage:=Result; GotCodepage:=true; end; function Utf2Cp1251(s:string):string; var i:integer; Skip,DSkip:boolean; begin //TODO Complete codepage conversion Skip:=false;DSkip:=false;Result:=''; for i:=1 to length(s) do begin if DSkip then begin Skip:=true;DSkip:=false;continue;end; if Skip then begin Skip:=false;Continue;end; if s[i]<#127 then begin Result:=Result+s[i];continue; end; if i=length(s) then break;//Do not translate 'strange' symbol if (s[i]=chr($D0)) and (s[i+1]>=chr($90))and (s[i+1]=chr($80))and (s[i+1]'+FN2); SL.LoadFromFile(FN2); if SL.Text<>'' then Result:=SL.Text else Result:=s; DeleteFile(FN1);DeleteFile(FN2); {$endif} end; end.