2014-11-20 13:21 GMT-03:00 Mattias Gaertner <[email protected]>:

>
> 2. The new mode: The LCL, FCL and RTL treat all "String" as UTF-8
> encoded. Most RTL file functions now work with full Unicode.
> For example FileExists and aStringList.LoadFromFile(Filename) now
> support full Unicode.
>

[..]

Please test and tell what you find out.
>
>
The FormatSettings fields are still encoded with System Code Page
regardless of DefaultSystemCodePage value.

While for english locales there's no problem, other locales like PT-BR have
accented names in days and monthes.

The problem is in windows SysUtils.GetLocaleStr function that uses non
unicode Win Api function. This problem will affect also the UnicodeString
RTL.

Attached is a test app that shows the issue. It also has a version of
GetLocaleStr that fixes the issue for the RTL (both versions)

Luiz
program TestUTF8FormatSettings;

{$mode objfpc}{$H+}

uses
  {$ifdef Windows}
  Windows,
  {$endif}
  Classes, sysutils;

{$ifdef Windows}
function GetLocaleStrTest(LID, LT: Longint; const Def: string): String;
var
  L: Integer;
  Buf: array[0..255] of WideChar;
  W: WideString;
begin
  L := GetLocaleInfoW(LID, LT, Buf, SizeOf(Buf));
  if L > 0 then
  begin
    //SetString(Result, PWideChar(@Buf[0]), L - 1) leads to wrong result
    //Bug in Procedure SetString (Out S : AnsiString; Buf : PWideChar; Len : SizeInt) ?
    SetString(W, PWideChar(@Buf[0]), L - 1);
    Result := W;
  end
  else
    Result := Def;
end;
{$endif}

var
  i: Integer;
  S: String;
  List: TStringList;
begin
  WriteLn('DefaultSystemCodePage: ', DefaultSystemCodePage);
  DefaultSystemCodePage:=CP_UTF8;
  DefaultRTLFileSystemCodePage:=CP_UTF8;
  List := TStringList.Create;
  for i := 1 to 12 do
  begin
    Write(StringCodePage(DefaultFormatSettings.LongMonthNames[i]), ' - ');
    WriteLn(DefaultFormatSettings.LongMonthNames[i]);
    List.Add(DefaultFormatSettings.LongMonthNames[i]);
  end;
  for i := 1 to 7 do
  begin
    Write(StringCodePage(DefaultFormatSettings.LongDayNames[i]), ' - ');
    WriteLn(DefaultFormatSettings.LongDayNames[i]);
    List.Add(DefaultFormatSettings.LongDayNames[i]);
  end;
  {$ifdef Windows}
  S := GetLocaleStrTest(GetThreadLocale, LOCALE_SDAYNAME1+1, 'xx');
  Write(StringCodePage(S), ' - ');
  WriteLn(S);
  List.Add(S);
  {$endif}

  List.SaveToFile('TestUTF8FormatSettingsOut.txt');
  List.Destroy;
end.

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to