mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-19 06:49:16 +02:00
* fall back to UTF-8 for darwin in unixcp.GetSystemCodePage if no LC_*/LANG
environment variables are set * if no LC_*/LANG environment variables are set, let cwstring fall back to unixcp.GetSystemCodePage o this is mainly to avoid problems on OS X, where under certain circumstances these variables are not set for GUI programs and as a result we set the system code page to ASCII git-svn-id: trunk@29257 -
This commit is contained in:
parent
3998c2f7fa
commit
63bd65942b
@ -993,6 +993,18 @@ begin
|
|||||||
ansi2pchar(temp,str,result);
|
ansi2pchar(temp,str,result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function envvarset(const varname: pchar): boolean;
|
||||||
|
var
|
||||||
|
varval: pchar;
|
||||||
|
begin
|
||||||
|
varval:=fpgetenv(varname);
|
||||||
|
result:=
|
||||||
|
assigned(varval) and
|
||||||
|
(varval[0]<>#0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function GetStandardCodePage(const stdcp: TStandardCodePageEnum): TSystemCodePage;
|
function GetStandardCodePage(const stdcp: TStandardCodePageEnum): TSystemCodePage;
|
||||||
var
|
var
|
||||||
langinfo: pchar;
|
langinfo: pchar;
|
||||||
@ -1004,15 +1016,25 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
langinfo:=nl_langinfo(CODESET);
|
{ if none of the relevant LC_* environment variables are set, fall back to
|
||||||
{ there's a bug in the Mac OS X 10.5 libc (based on FreeBSD's)
|
UTF-8 (this happens under some versions of OS X for GUI applications, which
|
||||||
that causes it to return an empty string of UTF-8 locales
|
otherwise get CP_ASCII) }
|
||||||
-> patch up (and in general, UTF-8 is a good default on
|
if envvarset('LC_ALL') or
|
||||||
Unix platforms) }
|
envvarset('LC_CTYPE') or
|
||||||
if not assigned(langinfo) or
|
envvarset('LANG') then
|
||||||
(langinfo^=#0) then
|
begin
|
||||||
langinfo:='UTF-8';
|
langinfo:=nl_langinfo(CODESET);
|
||||||
Result := GetCodepageByName(ansistring(langinfo));
|
{ there's a bug in the Mac OS X 10.5 libc (based on FreeBSD's)
|
||||||
|
that causes it to return an empty string of UTF-8 locales
|
||||||
|
-> patch up (and in general, UTF-8 is a good default on
|
||||||
|
Unix platforms) }
|
||||||
|
if not assigned(langinfo) or
|
||||||
|
(langinfo^=#0) then
|
||||||
|
langinfo:='UTF-8';
|
||||||
|
Result:=GetCodepageByName(ansistring(langinfo));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result:=unixcp.GetSystemCodepage;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$ifdef FPC_HAS_CPSTRING}
|
{$ifdef FPC_HAS_CPSTRING}
|
||||||
|
@ -714,7 +714,7 @@ var
|
|||||||
begin
|
begin
|
||||||
// Get one of non-empty environment variables in the next order:
|
// Get one of non-empty environment variables in the next order:
|
||||||
// LC_ALL, LC_CTYPE, LANG. Default is UTF-8 or ASCII.
|
// LC_ALL, LC_CTYPE, LANG. Default is UTF-8 or ASCII.
|
||||||
{$ifdef linux}
|
{$if defined(linux) or defined(darwin)}
|
||||||
Result:=CP_UTF8;
|
Result:=CP_UTF8;
|
||||||
{$else}
|
{$else}
|
||||||
Result:=CP_ASCII;
|
Result:=CP_ASCII;
|
||||||
|
Loading…
Reference in New Issue
Block a user