Преглед на файлове

* CP819/IBM819 should be mapped to Windows code page 28591 (ISO8859-1)
(mantis #30639)

git-svn-id: trunk@35397 -

Jonas Maebe преди 8 години
родител
ревизия
6d5339cdb6
променени са 3 файла, в които са добавени 95 реда и са изтрити 2 реда
  1. 1 0
      .gitattributes
  2. 2 2
      rtl/unix/unixcp.pp
  3. 92 0
      tests/webtbs/tw30639.pp

+ 1 - 0
.gitattributes

@@ -15325,6 +15325,7 @@ tests/webtbs/tw30572.pp svneol=native#text/plain
 tests/webtbs/tw30626.pp svneol=native#text/pascal
 tests/webtbs/tw30626b.pp svneol=native#text/pascal
 tests/webtbs/tw3063.pp svneol=native#text/plain
+tests/webtbs/tw30639.pp svneol=native#text/plain
 tests/webtbs/tw3064.pp svneol=native#text/plain
 tests/webtbs/tw30666.pp svneol=native#text/plain
 tests/webtbs/tw30706.pp svneol=native#text/plain

+ 2 - 2
rtl/unix/unixcp.pp

@@ -279,8 +279,6 @@ const
    (cp:1251; name:'MS-CYRL'),
    (cp:1251; name:'WINDOWS-1251'),
    (cp:1251; name:'windows-1251'), (* ANSI Cyrillic; Cyrillic (Windows) *)
-   (cp:1252; name:'CP819'),
-   (cp:1252; name:'IBM819'),
    (cp:1252; name:'CP1252'),
    (cp:1252; name:'MS-ANSI'),
    (cp:1252; name:'WINDOWS-1252'),
@@ -463,6 +461,8 @@ const
   {$ifdef aix}
    (cp:21866; name:'IBM-1124'), (* AIX *)
   {$endif}
+   (cp:28591; name:'CP819'),
+   (cp:28591; name:'IBM819'),
    (cp:28591; name:'ISO-8859-1'),
    (cp:28591; name:'ISO-IR-100'),
    (cp:28591; name:'ISO8859-1'),

+ 92 - 0
tests/webtbs/tw30639.pp

@@ -0,0 +1,92 @@
+program cp;
+
+{$mode objfpc}
+{$h+}
+{$codepage utf8}
+
+uses
+  SysUtils
+  {$ifdef unix}, cwstring
+  {$endif};
+
+type
+  string1252 = type ansistring(1252);
+
+function StrToHex(S: RawByteString): String;
+var
+  i: Integer;
+begin
+  Result := '';
+  for i := 1 to Length(S) do
+  begin
+    Result := Result + IntToHex(Ord(S[i]),2);
+    if i < Length(S) then Result := Result + #32;
+  end;
+end;
+
+function StrToHex(S: UnicodeString): String;
+var
+  i: Integer;
+begin
+  Result := '';
+  for i := 1 to Length(S) do
+  begin
+    Result := Result + IntToHex(Word(S[i]),4);
+    if i < Length(S) then Result := Result + #32;
+  end;
+end;
+
+function DebugString(S: RawByteString): String;
+begin
+  Result := Format('[%.5d] %s',[StringCodePage(S),StrToHex(S)]);
+end;
+
+function DebugString(S: UnicodeString): String;
+begin
+  Result := StrToHex(S);
+end;
+
+procedure Test(VarName: String; S: RawByteString; Expected: String);
+begin
+  write(VarName,': ',DebugString(S));
+  if StrToHex(S) = Expected then
+    writeln(': Ok')
+  else
+    writeln(': FAIL: Expected: ',Expected);
+end;
+
+procedure Test(VarName: String; S: UnicodeString; Expected: String);
+begin
+  write(VarName,': ',DebugString(S));
+  if StrToHex(S) = Expected then
+    writeln(': Ok')
+  else
+    writeln(': FAIL: Expected: ',Expected);
+end;
+
+
+var
+  s: string;
+  s1252: string1252;
+  sutf8: utf8string;
+  us: UnicodeString;
+
+begin
+  writeln('DefaultSystemCodePage = ',DefaultSystemCodePage);
+  sutf8 := #$E2#$82#$AC; //eur symbol in UTF8 encoding
+  Test('sutf8',sutf8,'E2 82 AC');
+
+  s := sutf8;
+  SetCodePage(RawBytestring(s), 1252, true);
+  Test('s    ', s, '80');
+
+  s1252 := sutf8;
+  Test('s1252', s1252, '80');
+
+  us := UnicodeString(sutf8);
+  Test('us   ', us, '20AC');
+
+  us := UnicodeString(s1252);
+  Test('us   ', us, '20AC');
+end.
+