|
@@ -137,7 +137,7 @@ Type
|
|
TFormatJSONContext = record
|
|
TFormatJSONContext = record
|
|
Options: TFormatOptions;
|
|
Options: TFormatOptions;
|
|
S: TJSONStringType; // .Join does not work very well for utf8string...
|
|
S: TJSONStringType; // .Join does not work very well for utf8string...
|
|
- {$ifndef Pas2JS} SUsed, {$endif} NCachedIndents, IndentSize: SizeInt;
|
|
|
|
|
|
+ {$ifndef Pas2JS} SUsed, {$endif} IndentSize: SizeInt;
|
|
CachedIndents: array of TJSONStringType;
|
|
CachedIndents: array of TJSONStringType;
|
|
procedure Append(const Piece: TJSONStringType);
|
|
procedure Append(const Piece: TJSONStringType);
|
|
procedure AppendIndent(I: SizeInt);
|
|
procedure AppendIndent(I: SizeInt);
|
|
@@ -1626,7 +1626,7 @@ begin
|
|
NPiece := Length(Piece);
|
|
NPiece := Length(Piece);
|
|
Inc(SUsed, NPiece);
|
|
Inc(SUsed, NPiece);
|
|
if SUsed > Length(S) then
|
|
if SUsed > Length(S) then
|
|
- SetLength(S, 128 + SUsed + SUsed shr 2 + SUsed shr 4);
|
|
|
|
|
|
+ SetLength(S, 128 + SUsed + SUsed shr 2 + SUsed shr 3);
|
|
Move(Pointer(Piece)^, (Pointer(S) + Start * SizeOf(S[1]))^, NPiece * SizeOf(S[1]));
|
|
Move(Pointer(Piece)^, (Pointer(S) + Start * SizeOf(S[1]))^, NPiece * SizeOf(S[1]));
|
|
end;
|
|
end;
|
|
{$else}
|
|
{$else}
|
|
@@ -1637,7 +1637,7 @@ end;
|
|
|
|
|
|
procedure TJSONData.TFormatJSONContext.AppendIndent(I: SizeInt);
|
|
procedure TJSONData.TFormatJSONContext.AppendIndent(I: SizeInt);
|
|
begin
|
|
begin
|
|
- if I <= 0 then exit; // Shortcut if 0.
|
|
|
|
|
|
+ if (I <= 0) or (IndentSize <= 0) then exit; // Shortcut if 0.
|
|
if (I >= Length(CachedIndents)) or (CachedIndents[I] = '') then
|
|
if (I >= Length(CachedIndents)) or (CachedIndents[I] = '') then
|
|
CreateCachedIndent(I);
|
|
CreateCachedIndent(I);
|
|
Append(CachedIndents[I]);
|
|
Append(CachedIndents[I]);
|
|
@@ -1648,7 +1648,7 @@ var
|
|
C: Char;
|
|
C: Char;
|
|
begin
|
|
begin
|
|
if I >= Length(CachedIndents) then
|
|
if I >= Length(CachedIndents) then
|
|
- SetLength(CachedIndents, 16 + I + I shr 2 + I shr 4);
|
|
|
|
|
|
+ SetLength(CachedIndents, 16 + I + I shr 2 + I shr 3);
|
|
C := ' ';
|
|
C := ' ';
|
|
if foUseTabChar in Options then
|
|
if foUseTabChar in Options then
|
|
C := #9;
|
|
C := #9;
|
|
@@ -1729,7 +1729,6 @@ begin
|
|
{$ifndef Pas2JS}
|
|
{$ifndef Pas2JS}
|
|
Ctx.SUsed := 0;
|
|
Ctx.SUsed := 0;
|
|
{$endif}
|
|
{$endif}
|
|
- Ctx.NCachedIndents := 0;
|
|
|
|
Ctx.IndentSize := IndentSize;
|
|
Ctx.IndentSize := IndentSize;
|
|
DoFormatJSON(Ctx, 0);
|
|
DoFormatJSON(Ctx, 0);
|
|
{$ifndef Pas2JS}
|
|
{$ifndef Pas2JS}
|