mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-04 19:30:32 +02:00
* Avoid reallocating string when parsing unicode char (bug ID 0037562)
git-svn-id: trunk@46412 -
This commit is contained in:
parent
8ae16284f2
commit
d6760f0ded
@ -939,10 +939,35 @@ begin
|
||||
Raise EConvertError.Create('Invalid JSON String:'+S);
|
||||
end;
|
||||
{$ELSE}
|
||||
|
||||
function BufferHexToInt(P : PAnsiChar): integer;
|
||||
var
|
||||
N, i: integer;
|
||||
ch: char;
|
||||
begin
|
||||
Result:= 0;
|
||||
for i:= 1 to 4 do
|
||||
begin
|
||||
ch:= p^;
|
||||
case ch of
|
||||
'0'..'9':
|
||||
N:= Ord(ch)-Ord('0');
|
||||
'a'..'f':
|
||||
N:= Ord(ch)-(Ord('a')-10);
|
||||
'A'..'F':
|
||||
N:= Ord(ch)-(Ord('A')-10);
|
||||
else
|
||||
exit(-1);
|
||||
end;
|
||||
Inc(P);
|
||||
Result:= Result*16+N;
|
||||
end;
|
||||
end;
|
||||
|
||||
Var
|
||||
|
||||
I,J,L,U1,U2 : Integer;
|
||||
App,W : String;
|
||||
App : String;
|
||||
|
||||
Procedure MaybeAppendUnicode;
|
||||
|
||||
@ -982,9 +1007,10 @@ begin
|
||||
'f' : App:=#12;
|
||||
'r' : App:=#13;
|
||||
'u' : begin
|
||||
W:=Copy(S,I+1,4);
|
||||
U2:=BufferHexToInt(PAnsiChar(@S[I+1]));
|
||||
if U2=-1 then
|
||||
Raise EJSON.Create('Invalid unicode hex code: '+Copy(S,I+1,4));
|
||||
Inc(I,4);
|
||||
u2:=StrToInt('$'+W);
|
||||
if (U1<>0) then
|
||||
begin
|
||||
App:={$IFDEF FPC_HAS_CPSTRING}UTF8Encode({$ENDIF}WideChar(U1)+WideChar(U2){$IFDEF FPC_HAS_CPSTRING}){$ENDIF};
|
||||
|
Loading…
Reference in New Issue
Block a user