pastojs: test #256+

This commit is contained in:
mattias 2020-12-19 11:38:03 +00:00
parent cf8c8652d4
commit 8aed6ac7e4
3 changed files with 15 additions and 7 deletions

View File

@ -923,6 +923,7 @@ end;
function UnicodeStrToCaption(const u: UnicodeString; MaxLength: integer function UnicodeStrToCaption(const u: UnicodeString; MaxLength: integer
): Unicodestring; ): Unicodestring;
// encode a string as a Pascal string literal using '' and #
var var
InLit: boolean; InLit: boolean;
Len: integer; Len: integer;
@ -4158,7 +4159,7 @@ function TResExprEvaluator.EvalPrimitiveExprString(Expr: TPrimitiveExpr
var var
h: RawByteString; h: RawByteString;
begin begin
if ((u>255) or (ForceUTF16)) and (Result.Kind=revkString) then if ((u>255) or ForceUTF16) and (Result.Kind=revkString) then
begin begin
// switch to unicodestring // switch to unicodestring
h:=TResEvalString(Result).S; h:=TResEvalString(Result).S;
@ -4285,7 +4286,7 @@ begin
end; end;
if p=StartP then if p=StartP then
RaiseInternalError(20170523123806); RaiseInternalError(20170523123806);
AddHash(u,false); AddHash(u,(S[StartP]='0') and (u>0));
end; end;
end; end;
'^': '^':

View File

@ -6513,9 +6513,10 @@ function TPas2JSResolver.ExtractPasStringLiteral(El: TPasElement;
S is a Pascal string literal e.g. 'Line'#10 S is a Pascal string literal e.g. 'Line'#10
'' empty string '' empty string
'''' => "'" '''' => "'"
#decimal #decimal #0..255 is UTF-8 byte, #01..0255 is UTF-16, #256+ is UTF-16
#$hex #$hex #$0..$ff is UTF-8 byte, #$01..$0FF is UTF-16, #$100+ is UTF-16
^l l is a letter a-z ^l l is a letter a-z
Invalid UTF-8 sequences give an error
} }
var var
p, StartP, i, l: integer; p, StartP, i, l: integer;
@ -6543,7 +6544,7 @@ begin
'''': '''':
begin begin
if p>StartP then if p>StartP then
Result:=Result+StrToJSString(copy(S,StartP,p-StartP)); Result:=Result+StrToJSString(copy(S,StartP,p-StartP)); // todo error on invalid UTF-8 sequence
inc(p); inc(p);
StartP:=p; StartP:=p;
if (p>l) or (S[p]<>'''') then if (p>l) or (S[p]<>'''') then
@ -6557,10 +6558,11 @@ begin
end; end;
until false; until false;
if p>StartP then if p>StartP then
Result:=Result+StrToJSString(copy(S,StartP,p-StartP)); Result:=Result+StrToJSString(copy(S,StartP,p-StartP)); // todo error on invalid UTF-8 sequence
end; end;
'#': '#':
begin begin
// byte or word sequence
inc(p); inc(p);
if p>l then if p>l then
RaiseInternalError(20170207155121); RaiseInternalError(20170207155121);

View File

@ -7467,6 +7467,7 @@ begin
' c:=#$DFFF;', // invalid UTF-16 ' c:=#$DFFF;', // invalid UTF-16
' c:=#$FFFF;', // last UCS-2 ' c:=#$FFFF;', // last UCS-2
' c:=high(c);', // last UCS-2 ' c:=high(c);', // last UCS-2
' c:=#269;',
'']); '']);
ConvertProgram; ConvertProgram;
CheckSource('TestCharConst', CheckSource('TestCharConst',
@ -7497,6 +7498,7 @@ begin
'$mod.c="\uDFFF";', '$mod.c="\uDFFF";',
'$mod.c="\uFFFF";', '$mod.c="\uFFFF";',
'$mod.c="\uFFFF";', '$mod.c="\uFFFF";',
'$mod.c = "č";',
''])); '']));
end; end;
@ -7607,9 +7609,11 @@ begin
' s:=''"''''"'';', ' s:=''"''''"'';',
' s:=#$20AC;', // euro ' s:=#$20AC;', // euro
' s:=#$10437;', // outside BMP ' s:=#$10437;', // outside BMP
//' s:=#$F0#$90#$90#$B7;', // as UTF-8
' s:=default(string);', ' s:=default(string);',
' s:=concat(s);', ' s:=concat(s);',
' s:=concat(s,''a'',s)', ' s:=concat(s,''a'',s);',
//' s:=#0250#269;',
'']); '']);
ConvertProgram; ConvertProgram;
CheckSource('TestStringConst', CheckSource('TestStringConst',
@ -7631,6 +7635,7 @@ begin
'$mod.s=''"\''"'';', '$mod.s=''"\''"'';',
'$mod.s="€";', '$mod.s="€";',
'$mod.s="'#$F0#$90#$90#$B7'";', '$mod.s="'#$F0#$90#$90#$B7'";',
//'$mod.s="'#$F0#$90#$90#$B7'";',
'$mod.s="";', '$mod.s="";',
'$mod.s = $mod.s;', '$mod.s = $mod.s;',
'$mod.s = $mod.s.concat("a", $mod.s);', '$mod.s = $mod.s.concat("a", $mod.s);',