fpc/tests/test/tcpstr18.pp
paul c1866d5c17 compiler:
- don't pass CP_NONE encoding to internal functions. They handled it as 0 encoding. This will optimize the generated code a bit.
  - convert all king of string/char/pchar constants to local ansistring def if they needs to be passed to rawbytestring type. They should not get a CP_NONE codepage (delphi compatible)
  - don't convert left and right arguments of string concatenation to ansistring type if they are already ansistrings but with different codepage - RTL already handles different codepages in concat routine
  - fix resultdef for ansistring concatenations inside assignments - return def of left assignment operand if it is already ansistring - this reduces amount of unneeded condepage conversions since concat functions can return result in any desired codepage
rtl: remove CP_NONE comparisions from most of RTL functions, replace 0 constant with CP_ACP
tests: add test to check various conversions to RawByteString type

git-svn-id: trunk@19519 -
2011-10-20 09:25:51 +00:00

42 lines
943 B
ObjectPascal

// to have correct test result with delphi set codepage option to 866
program tcpstr17;
{$apptype console}
{$ifdef fpc}
{$mode delphi}
{$codepage cp866}
{$endif}
{$ifdef unix}
uses
cwstring;
{$endif}
procedure TestRawByte(const Source: RawByteString; cp: word; const reason: integer);
begin
Writeln(StringCodePage(Source), ' ', Source);
if StringCodePage(Source) <> cp then
halt(reason);
end;
const
test: array[0..4] of ansichar = 'test'#0;
var
s: rawbytestring;
ss: shortstring;
c: ansichar;
w: widechar;
begin
s := 'test';
ss := 'test';
TestRawByte(s, 866, 1);
TestRawByte(ss, DefaultSystemCodePage, 2);
TestRawByte(AnsiChar('t'), 866, 3);
c := 't';
TestRawByte(c, DefaultSystemCodePage, 4);
TestRawByte(WideChar('t'), 866, 5);
w := 't';
TestRawByte(w, DefaultSystemCodePage, 6);
TestRawByte(test, DefaultSystemCodePage, 7);
TestRawByte(PAnsiChar(@test[0]), DefaultSystemCodePage, 8);
end.