fpc/tests/test/twrstr9.pp
Jonas Maebe d2b8275b99 + support for arbitrary encodings in readstr/writestr
o set the code page of the temporary "text" file to utf-8 for writestr with
     unicodestring/widestring as destination, so that no data loss can occur
     (+ properly deal with cases whereby part of an utf-8 character is
      written to the textbuf in this case)
   o explicitly pass the code page of the destination ansistring for writestr
     with ansistring as destination and set it for the temporary "text" file
   o set the code page of the text file for readstr

git-svn-id: trunk@26317 -
2013-12-29 19:18:49 +00:00

34 lines
675 B
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{$codepage utf8}
{$ifdef unix}
uses
cwstring;
{$endif}
type
ts866 = type ansistring(866);
var
u: unicodestring;
s: utf8string;
rs: ts866;
p: pointer;
i: longint;
begin
DefaultSystemCodePage:=CP_ASCII;
s:='§èà£ù';
rs:=ts866('Популярные фото');
writestr(u,s,1,s,rs);
if u <>'§èà£ù1§èà£ùПопулярные фото' then
halt(1);
getmem(p,length(s)-1);
s:='';
for i:=1 to (256 div 3) do
s:=s+utf8string('㒨');
s:=s+utf8string('㒨');
{ check that splitting the last 㒨 into two parts during writestr doesn't cause a
conversion error }
writestr(u,s);
if utf8string(u)<>s then
halt(2);
end.