Skip to content

Commit 00fa153

Browse files
committed
Honor NSJSONWritingPrettyPrinted
1 parent 0e31e4d commit 00fa153

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Source/NSJSONSerialization.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,17 @@
840840
static NSMutableCharacterSet *escapeSet;
841841

842842
static inline void
843-
writeTabs(NSMutableString *output, NSInteger tabs)
843+
writeTabs(NSMutableString *output, NSInteger tabs, NSUInteger opt)
844844
{
845-
NSInteger i;
846-
847-
for (i = 0 ; i < tabs ; i++)
845+
if (opt & NSJSONWritingPrettyPrinted)
848846
{
849-
[output appendString: @"\t"];
847+
NSInteger i;
848+
849+
for (i = 0 ; i < tabs ; i++)
850+
{
851+
// [output appendString: @"\t"];
852+
[output appendString: @" "]; // One tabstop is two spaces
853+
}
850854
}
851855
}
852856

@@ -873,11 +877,11 @@
873877
}
874878
writeComma = YES;
875879
writeNewline(output, tabs);
876-
writeTabs(output, tabs);
880+
writeTabs(output, tabs, opt);
877881
writeObject(o, output, tabs + 1, opt);
878882
END_FOR_IN(obj)
879883
writeNewline(output, tabs);
880-
writeTabs(output, tabs);
884+
writeTabs(output, tabs, opt);
881885
[output appendString: @"]"];
882886
}
883887
else if ([obj isKindOfClass: NSDictionaryClass])
@@ -900,14 +904,14 @@
900904
}
901905
writeComma = YES;
902906
writeNewline(output, tabs);
903-
writeTabs(output, tabs);
907+
writeTabs(output, tabs, opt);
904908
writeObject(o, output, tabs + 1, opt);
905909
[output appendString: @":"];
906910
writeObject([obj objectForKey: o], output, tabs + 1, opt);
907911
END_FOR_IN(keys)
908912

909913
writeNewline(output, tabs);
910-
writeTabs(output, tabs);
914+
writeTabs(output, tabs, opt);
911915
[output appendString: @"}"];
912916
}
913917
else if ([obj isKindOfClass: NSStringClass])

0 commit comments

Comments
 (0)