mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 17:39:24 +02:00

- add helper function getansistringcodepage which returns explicitly set codepage or 0 in other case - add helper function getansistringdef which return a def with explicitly set codepage or cansistringtype in other case - change tstoreddef.createnai constructor to allow set codepage in constructor - don't convert string constants to rawbytestring. if string constant already has a codepage - preserve it or convert to ansistring codepage (delphi compatible) - don't perform string conversion from ansistring to strings with explicitly set codepage (by directive or by compiler switch) and vice versa (delphi compatible) + test which covers most of the cases git-svn-id: trunk@19510 -
66 lines
1.6 KiB
ObjectPascal
66 lines
1.6 KiB
ObjectPascal
// to have correct test result with delphi set codepage option to 65001
|
|
program tcpstr17;
|
|
{$ifdef FPC}
|
|
{$mode delphi}
|
|
{$codepage utf8}
|
|
{$endif}
|
|
{$apptype console}
|
|
type
|
|
TOEMStr = type AnsiString(866);
|
|
{$ifndef FPC}
|
|
TSystemCodePage = Word;
|
|
const
|
|
CP_UTF8 = 65001;
|
|
{$endif}
|
|
|
|
procedure TestCodeConvRaw(const s: rawbytestring; const CodePage: TSystemCodePage);
|
|
begin
|
|
WriteLn(StringCodePage(s), ' ',s);
|
|
if CodePage <> StringCodePage(s) then
|
|
halt(1);
|
|
end;
|
|
|
|
procedure TestCodeConvAnsi(const s: ansistring; const CodePage: TSystemCodePage);
|
|
begin
|
|
WriteLn(StringCodePage(s), ' ',s);
|
|
if CodePage <> StringCodePage(s) then
|
|
halt(2);
|
|
end;
|
|
|
|
procedure TestCodeConvUTF(const s: utf8string; const CodePage: TSystemCodePage);
|
|
begin
|
|
WriteLn(StringCodePage(s), ' ',s);
|
|
if CodePage <> StringCodePage(s) then
|
|
halt(3);
|
|
end;
|
|
|
|
var
|
|
u: unicodestring;
|
|
u8: utf8string;
|
|
s: ansistring;
|
|
oemstr: TOEMStr;
|
|
begin
|
|
u := #$0141#$00F3#$0064#$017A;
|
|
u8 := u;
|
|
TestCodeConvRaw(u8, CP_UTF8);
|
|
// if UTF8 codepage is set in options S will have UTF8 codepage
|
|
s := u8;
|
|
TestCodeConvRaw(s, CP_UTF8);
|
|
TestCodeConvAnsi(u8, CP_UTF8);
|
|
TestCodeConvAnsi(s, CP_UTF8);
|
|
// converts to 866
|
|
oemstr := u8;
|
|
TestCodeConvRaw(oemstr, 866);
|
|
TestCodeConvAnsi(oemstr, DefaultSystemCodePage);
|
|
s := 'test';
|
|
TestCodeConvRaw(s, CP_UTF8);
|
|
// converts to System codepage
|
|
s := oemstr;
|
|
TestCodeConvRaw(s, DefaultSystemCodePage);
|
|
TestCodeConvUTF(s, DefaultSystemCodePage);
|
|
// outputs in source codepage instead of OEM
|
|
TestCodeConvRaw('привет', CP_UTF8);
|
|
// outputs in OEM codepage
|
|
TestCodeConvRaw(TOEMStr('привет'), 866);
|
|
end.
|