mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 20:20:39 +02:00
lcl: fix GetEnvironmentVariableUTF8 for Windows, returning wrong string for OEM encoded values
git-svn-id: trunk@26586 -
This commit is contained in:
parent
56bf0c43a2
commit
a13d9ca23e
@ -187,6 +187,7 @@ 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 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)
|
||||
|
||||
// file operations
|
||||
|
@ -82,6 +82,23 @@ begin
|
||||
Result := s;
|
||||
end;
|
||||
|
||||
function ConsoleToUTF8(const s: string): string;// converts UTF8 string to console encoding (used by Write, WriteLn)
|
||||
{$ifdef MSWindows}
|
||||
var
|
||||
Dst: PChar;
|
||||
{$endif}
|
||||
begin
|
||||
{$ifdef MSWindows}
|
||||
Dst := AllocMem((Length(s) + 1) * SizeOf(Char));
|
||||
if OemToChar(PChar(s), Dst) then
|
||||
Result := StrPas(Dst)
|
||||
else
|
||||
Result := s;
|
||||
FreeMem(Dst);
|
||||
{$endif}
|
||||
Result := SysToUTF8(Result);
|
||||
end;
|
||||
|
||||
function UTF8ToConsole(const s: string): string;
|
||||
{$ifdef MSWindows}
|
||||
var
|
||||
@ -244,12 +261,18 @@ end;
|
||||
|
||||
function GetEnvironmentStringUTF8(Index: Integer): String;
|
||||
begin
|
||||
Result:=SysToUTF8(SysUtils.GetEnvironmentString(Index));
|
||||
// on Windows SysUtils.GetEnvironmentString returns OEM encoded string
|
||||
// so ConsoleToUTF8 function should be used!
|
||||
// RTL issue: http://bugs.freepascal.org/view.php?id=15233
|
||||
Result:=ConsoleToUTF8(SysUtils.GetEnvironmentString(Index));
|
||||
end;
|
||||
|
||||
function GetEnvironmentVariableUTF8(const EnvVar: String): String;
|
||||
begin
|
||||
Result:=SysToUTF8(SysUtils.GetEnvironmentVariable(UTF8ToSys(EnvVar)));
|
||||
// on Windows SysUtils.GetEnvironmentString returns OEM encoded string
|
||||
// so ConsoleToUTF8 function should be used!
|
||||
// RTL issue: http://bugs.freepascal.org/view.php?id=15233
|
||||
Result:=ConsoleToUTF8(SysUtils.GetEnvironmentVariable(UTF8ToSys(EnvVar)));
|
||||
end;
|
||||
|
||||
function GetAppConfigDirUTF8(Global: Boolean): string;
|
||||
|
Loading…
Reference in New Issue
Block a user