mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 12:49:33 +02:00

determine the length of a multi-byte character. The return values are defined to be the same as those of POSIX' mblen: -1 = invalid/incomplete sequence, 0 = #0, > 0 = length of sequence in bytes. + default implementation for widestringmanager.codepointlengthproc (assumes all code points have length 1) and Unix implementation (based on mb(r)len); Windows implementation is still required * replaced default implementation of widestringmanager.CharLengthPCharProc with strlen() of the input instead of an error (correct if all code points have length 1, still needs Windows implementation) + implemented fpc_text_read_{wide,unicode}str() and fpc_text_read_widechar() (mantis #18163); fpc_text_read_widechar() uses the new widestringmanager.codepointlengthproc() + unicodestring support for readstr/writestr * fixed declaration of fpc_Write_Text_UnicodeStr (unicodestring instead of widestring parameter) * extended test/twide*.pp tests to test the new/fixed functionality git-svn-id: trunk@16533 -
81 lines
1.3 KiB
ObjectPascal
81 lines
1.3 KiB
ObjectPascal
{ %skiptarget=win32,win64,wince }
|
|
{ This test is only useful if the local codepage is utf-8 which
|
|
usually not the case on windows
|
|
}
|
|
{$codepage utf-8}
|
|
|
|
{$mode objfpc}
|
|
|
|
uses
|
|
{$ifdef unix}
|
|
cwstring,
|
|
{$endif}
|
|
SysUtils;
|
|
|
|
{$i+}
|
|
|
|
var
|
|
t: text;
|
|
w: widestring;
|
|
u: unicodestring;
|
|
a: ansistring;
|
|
wc: widechar;
|
|
|
|
begin
|
|
assign(t,'twide3.txt');
|
|
rewrite(t);
|
|
writeln(t,'łóżka');
|
|
close(t);
|
|
reset(t);
|
|
|
|
try
|
|
read(t,wc);
|
|
if wc<>'ł' then
|
|
raise Exception.create('wrong widechar read: '+inttostr(ord(wc))+'<>'+inttostr(ord('ł')));
|
|
except
|
|
close(t);
|
|
// erase(t);
|
|
raise;
|
|
end;
|
|
|
|
reset(t);
|
|
try
|
|
readln(t,a);
|
|
w:=a;
|
|
if (w<>'łóżka') then
|
|
raise Exception.create('wrong ansistring read');
|
|
except
|
|
close(t);
|
|
erase(t);
|
|
raise;
|
|
end;
|
|
|
|
reset(t);
|
|
try
|
|
readln(t,w);
|
|
if (w<>'łóżka') then
|
|
raise Exception.create('wrong widestring read');
|
|
except
|
|
close(t);
|
|
erase(t);
|
|
raise;
|
|
end;
|
|
|
|
reset(t);
|
|
try
|
|
readln(t,u);
|
|
if (u<>'łóżka') then
|
|
raise Exception.create('wrong unicodestring read');
|
|
finally
|
|
close(t);
|
|
erase(t);
|
|
end;
|
|
|
|
readstr(u,a);
|
|
if u<>a then
|
|
raise Exception.create('wrong readstr(u,a)');
|
|
readstr(w,a);
|
|
if w<>u then
|
|
raise Exception.create('wrong readstr(w,a)');
|
|
end.
|