@@ -590,7 +590,7 @@ struct Parser {
590590
591591 private mutating func _parseString( index: Int ) throws -> ( String ? , Int ) {
592592 // skip first '\"' character
593- var cursor = eatWhiteSpace ( index) . successor ( )
593+ var cursor = index. successor ( )
594594
595595 tempStringBuffer. removeAll ( keepCapacity: true )
596596
@@ -703,17 +703,6 @@ struct Parser {
703703 return ( token, cursor)
704704 }
705705
706- private func getLastIndexOfNumber( index: Int ) -> Int {
707- for lastIndex in Range ( start: index, end: string. endIndex) {
708- switch ( string [ lastIndex] ) {
709- // -4.2e3 +12E4
710- case Parser . minus, Parser . plus, Parser . _0, Parser . _1, Parser . _2, Parser . _3, Parser . _4, Parser . _5, Parser . _6, Parser . _7, Parser . _8, Parser . _9, Parser . e, Parser . E, Parser . dot: continue
711- default : return lastIndex
712- }
713- }
714- return string. endIndex
715- }
716-
717706 private mutating func parseValue( index: Int ) throws -> ( JSON , Int ) {
718707 let ( token, cursor) = nextToken ( index)
719708
@@ -753,7 +742,7 @@ struct Parser {
753742 }
754743
755744 private mutating func parseNumber( index: Int ) throws -> ( JSON , Int ) {
756- let cursor = eatWhiteSpace ( index)
745+ let cursor = index
757746
758747 if let ( double, distance) = parseDouble ( string. baseAddress. advancedBy ( cursor) ) {
759748 return ( JSON ( double) , cursor + distance)
@@ -762,7 +751,7 @@ struct Parser {
762751 }
763752
764753 private func parseNull( index: Int ) throws -> ( JSON , Int ) {
765- var cursor = eatWhiteSpace ( index)
754+ var cursor = index
766755
767756 guard cursor != string. endIndex && string [ cursor] == Parser . n else {
768757 throw ParseError ( " invalid json: expect 'null' at \( cursor) " )
@@ -784,7 +773,7 @@ struct Parser {
784773 }
785774
786775 private func parseTrue( index: Int ) throws -> ( JSON , Int ) {
787- var cursor = eatWhiteSpace ( index)
776+ var cursor = index
788777
789778 guard cursor != string. endIndex && string [ cursor] == Parser . t else {
790779 throw ParseError ( " invalid json: expect 'true' at \( cursor) " )
@@ -806,7 +795,7 @@ struct Parser {
806795 }
807796
808797 private func parseFalse( index: Int ) throws -> ( JSON , Int ) {
809- var cursor = eatWhiteSpace ( index)
798+ var cursor = index
810799
811800 guard cursor != string. endIndex && string [ cursor] == Parser . f else {
812801 throw ParseError ( " invalid json: expect 'false' at \( cursor) " )
@@ -831,7 +820,7 @@ struct Parser {
831820 }
832821
833822 private mutating func parseArray( index: Int ) throws -> ( JSON , Int ) {
834- var cursor = eatWhiteSpace ( index)
823+ var cursor = index
835824
836825 guard string [ cursor] == Parser . leftbracket else {
837826 // invalid json "[" start array
@@ -874,7 +863,7 @@ struct Parser {
874863 }
875864
876865 private mutating func parseObject( index: Int ) throws -> ( JSON , Int ) {
877- var cursor = eatWhiteSpace ( index)
866+ var cursor = index
878867
879868 guard string [ cursor] == Parser . leftbrace else {
880869 // invalid json "{" start array
@@ -893,7 +882,7 @@ struct Parser {
893882 }
894883
895884 while cursor != string. endIndex {
896- let ( _key, afterKey) = try _parseString ( cursor)
885+ let ( _key, afterKey) = try _parseString ( eatWhiteSpace ( cursor) )
897886 guard let key = _key else {
898887 // parse key error, invalid json
899888 throw ParseError ( " invalid json: expect string at \( cursor) " )
0 commit comments