Skip to content

Commit f2272aa

Browse files
argonparkera
authored andcommitted
Treat string parsing as a special case (#341)
`consumeStructure` should be simple with no knowledge of the special requirements for string parsing. We'll handle it directly in `parseString` instead.
1 parent 7b173d0 commit f2272aa

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Foundation/NSJSONSerialization.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,7 @@ private struct JSONReader {
484484
}
485485

486486
func consumeStructure(_ ascii: UInt8, input: Index) throws -> Index? {
487-
switch ascii {
488-
case Structure.QuotationMark:
489-
return try consumeWhitespace(input).flatMap(consumeASCII(ascii)) // for strings we don't consume(ignore) the whitespaces after the starting Quotation Mark because they are part of string e.g in "{\"title\" : \" hello world!!\" }" the value should be " hello world!!" instead of "hello world"
490-
default:
491-
return try consumeWhitespace(input).flatMap(consumeASCII(ascii)).flatMap(consumeWhitespace)
492-
}
487+
return try consumeWhitespace(input).flatMap(consumeASCII(ascii)).flatMap(consumeWhitespace)
493488
}
494489

495490
func consumeASCII(_ ascii: UInt8) -> (Index) throws -> Index? {
@@ -530,7 +525,7 @@ private struct JSONReader {
530525
//MARK: - String Parsing
531526

532527
func parseString(_ input: Index) throws -> (String, Index)? {
533-
guard let beginIndex = try consumeStructure(Structure.QuotationMark, input: input) else {
528+
guard let beginIndex = try consumeWhitespace(input).flatMap(consumeASCII(Structure.QuotationMark)) else {
534529
return nil
535530
}
536531
var chunkIndex: Int = beginIndex

0 commit comments

Comments
 (0)