@@ -30,7 +30,7 @@ public static JsonValue Parse(TextReader reader)
3030 {
3131 if ( reader == null )
3232 {
33- throw new ArgumentNullException ( " reader" ) ;
33+ throw new ArgumentNullException ( nameof ( reader ) ) ;
3434 }
3535
3636 return new JsonReader ( reader ) . Parse ( ) ;
@@ -45,12 +45,12 @@ public static JsonValue Parse(string source)
4545 {
4646 if ( source == null )
4747 {
48- throw new ArgumentNullException ( " source" ) ;
48+ throw new ArgumentNullException ( nameof ( source ) ) ;
4949 }
5050
5151 using ( var reader = new StringReader ( source ) )
5252 {
53- return new JsonReader ( reader ) . Parse ( ) ;
53+ return Parse ( reader ) ;
5454 }
5555 }
5656
@@ -112,14 +112,9 @@ private JsonValue ReadBoolean()
112112 this . scanner . Assert ( "true" ) ;
113113 return true ;
114114
115- case 'f' :
115+ default :
116116 this . scanner . Assert ( "false" ) ;
117117 return false ;
118-
119- default :
120- throw new JsonParseException (
121- ErrorType . InvalidOrUnexpectedCharacter ,
122- this . scanner . Position ) ;
123118 }
124119 }
125120
@@ -191,10 +186,12 @@ private string ReadString()
191186
192187 while ( true )
193188 {
189+ var errorPosition = this . scanner . Position ;
194190 var c = this . scanner . Read ( ) ;
195191
196192 if ( c == '\\ ' )
197193 {
194+ errorPosition = this . scanner . Position ;
198195 c = this . scanner . Read ( ) ;
199196
200197 switch ( char . ToLower ( c ) )
@@ -225,7 +222,7 @@ private string ReadString()
225222 default :
226223 throw new JsonParseException (
227224 ErrorType . InvalidOrUnexpectedCharacter ,
228- this . scanner . Position ) ;
225+ errorPosition ) ;
229226 }
230227 }
231228 else if ( c == '"' )
@@ -238,7 +235,7 @@ private string ReadString()
238235 {
239236 throw new JsonParseException (
240237 ErrorType . InvalidOrUnexpectedCharacter ,
241- this . scanner . Position ) ;
238+ errorPosition ) ;
242239 }
243240 else
244241 {
@@ -252,6 +249,7 @@ private string ReadString()
252249
253250 private int ReadHexDigit ( )
254251 {
252+ var errorPosition = this . scanner . Position ;
255253 switch ( char . ToUpper ( this . scanner . Read ( ) ) )
256254 {
257255 case '0' :
@@ -305,7 +303,7 @@ private int ReadHexDigit()
305303 default :
306304 throw new JsonParseException (
307305 ErrorType . InvalidOrUnexpectedCharacter ,
308- this . scanner . Position ) ;
306+ errorPosition ) ;
309307 }
310308 }
311309
@@ -342,13 +340,14 @@ private JsonObject ReadObject(JsonObject jsonObject)
342340 {
343341 this . scanner . SkipWhitespace ( ) ;
344342
343+ var errorPosition = this . scanner . Position ;
345344 var key = this . ReadJsonKey ( ) ;
346345
347346 if ( jsonObject . ContainsKey ( key ) )
348347 {
349348 throw new JsonParseException (
350349 ErrorType . DuplicateObjectKeys ,
351- this . scanner . Position ) ;
350+ errorPosition ) ;
352351 }
353352
354353 this . scanner . SkipWhitespace ( ) ;
@@ -363,6 +362,7 @@ private JsonObject ReadObject(JsonObject jsonObject)
363362
364363 this . scanner . SkipWhitespace ( ) ;
365364
365+ errorPosition = this . scanner . Position ;
366366 var next = this . scanner . Read ( ) ;
367367 if ( next == ',' )
368368 {
@@ -386,7 +386,7 @@ private JsonObject ReadObject(JsonObject jsonObject)
386386 {
387387 throw new JsonParseException (
388388 ErrorType . InvalidOrUnexpectedCharacter ,
389- this . scanner . Position ) ;
389+ errorPosition ) ;
390390 }
391391 }
392392 }
@@ -421,6 +421,7 @@ private JsonArray ReadArray(JsonArray jsonArray)
421421
422422 this . scanner . SkipWhitespace ( ) ;
423423
424+ var errorPosition = this . scanner . Position ;
424425 var next = this . scanner . Read ( ) ;
425426 if ( next == ',' )
426427 {
@@ -444,7 +445,7 @@ private JsonArray ReadArray(JsonArray jsonArray)
444445 {
445446 throw new JsonParseException (
446447 ErrorType . InvalidOrUnexpectedCharacter ,
447- this . scanner . Position ) ;
448+ errorPosition ) ;
448449 }
449450 }
450451 }
0 commit comments