fcl-json: faster read /u

git-svn-id: trunk@38256 -
This commit is contained in:
Mattias Gaertner 2018-02-16 19:17:55 +00:00
parent f3c7642384
commit ae3a735e51

View File

@ -208,8 +208,8 @@ var
TokenStart: PChar; TokenStart: PChar;
it : TJSONToken; it : TJSONToken;
I : Integer; I : Integer;
OldLength, SectionLength, tstart,tcol: Integer; OldLength, SectionLength, tstart,tcol, u: Integer;
C : char; C , c2: char;
S : String; S : String;
IsStar,EOC: Boolean; IsStar,EOC: Boolean;
@ -272,21 +272,24 @@ begin
'/' : S:='/'; '/' : S:='/';
'u' : begin 'u' : begin
S:='0000'; S:='0000';
u:=0;
For I:=1 to 4 do For I:=1 to 4 do
begin begin
Inc(TokenStr); Inc(TokenStr);
Case TokenStr[0] of c2:=TokenStr^;
'0'..'9','A'..'F','a'..'f' : Case c2 of
S[i]:=Upcase(TokenStr[0]); '0'..'9': u:=u*16+ord(c2)-ord('0');
'A'..'F': u:=u*16+ord(c2)-ord('A')+10;
'a'..'f': u:=u*16+ord(c2)-ord('a')+10;
else else
Error(SErrInvalidCharacter, [CurRow,CurColumn,TokenStr[0]]); Error(SErrInvalidCharacter, [CurRow,CurColumn,TokenStr[0]]);
end; end;
end; end;
// WideChar takes care of conversion... // ToDo: 4-bytes UTF16
if (joUTF8 in Options) then if (joUTF8 in Options) or (DefaultSystemCodePage=CP_UTF8) then
S:=Utf8Encode(WideString(WideChar(StrToInt('$'+S)))) S:=Utf8Encode(WideString(WideChar(u))) // ToDo: use faster function
else else
S:=WideChar(StrToInt('$'+S)); S:=String(WideChar(u)); // WideChar converts the encoding. Should it warn on loss?
end; end;
#0 : Error(SErrOpenString); #0 : Error(SErrOpenString);
else else
@ -298,7 +301,6 @@ begin
Move(S[1],FCurTokenString[OldLength + SectionLength+1],Length(S)); Move(S[1],FCurTokenString[OldLength + SectionLength+1],Length(S));
Inc(OldLength, SectionLength+Length(S)); Inc(OldLength, SectionLength+Length(S));
// Next char // Next char
// Inc(TokenStr);
TokenStart := TokenStr+1; TokenStart := TokenStr+1;
end; end;
if TokenStr[0] = #0 then if TokenStr[0] = #0 then