@@ -269,8 +269,8 @@ function applyobject(keyvalfunc, x::LazyValues)
269269 @nextbyte
270270 b == UInt8 (' }' ) && return pos + 1
271271 while true
272- # applystring returns key as a PtrString
273- key, pos = @inline applystring ( nothing , LazyValue (buf, pos, JSONTypes. STRING, getopts (x), false ))
272+ # parsestring returns key as a PtrString
273+ key, pos = @inline parsestring ( LazyValue (buf, pos, JSONTypes. STRING, getopts (x), false ))
274274 @nextbyte
275275 if b != UInt8 (' :' )
276276 error = ExpectedColon
@@ -455,7 +455,7 @@ StructUtils.keyeq(x::PtrString, y::Symbol) = convert(Symbol, x) == y
455455# or not. It allows materialize, _binary, etc. to deal
456456# with the string data appropriately without forcing a String allocation
457457# PtrString should NEVER be visible to users though!
458- function applystring (f, x:: LazyValue )
458+ function parsestring ( x:: LazyValue )
459459 buf, pos = getbuf (x), getpos (x)
460460 len, b = getlength (buf), getbyte (buf, pos)
461461 if b != UInt8 (' "' )
@@ -483,12 +483,7 @@ function applystring(f, x::LazyValue)
483483 @nextbyte (false )
484484 end
485485 str = PtrString (pointer (buf, spos), pos - spos, escaped)
486- if f === nothing
487- return str, pos + 1
488- else
489- f (str)
490- return pos + 1
491- end
486+ return str, pos + 1
492487
493488@label invalid
494489 invalid (error, buf, pos, " string" )
@@ -525,7 +520,30 @@ macro check_special(special, value)
525520 end )
526521end
527522
528- function applynumber (valfunc, x:: LazyValue )
523+ const INT = 0x00
524+ const FLOAT = 0x01
525+ const BIGINT = 0x02
526+ const BIGFLOAT = 0x03
527+ const BIG_ZERO = BigInt (0 )
528+
529+ struct NumberResult
530+ tag:: UInt8
531+ int:: Int64
532+ float:: Float64
533+ bigint:: BigInt
534+ bigfloat:: BigFloat
535+ NumberResult (int:: Int64 ) = new (INT, int)
536+ NumberResult (float:: Float64 ) = new (FLOAT, Int64 (0 ), float)
537+ NumberResult (bigint:: BigInt ) = new (BIGINT, Int64 (0 ), 0.0 , bigint)
538+ NumberResult (bigfloat:: BigFloat ) = new (BIGFLOAT, Int64 (0 ), 0.0 , BIG_ZERO, bigfloat)
539+ end
540+
541+ isint (x:: NumberResult ) = x. tag == INT
542+ isfloat (x:: NumberResult ) = x. tag == FLOAT
543+ isbigint (x:: NumberResult ) = x. tag == BIGINT
544+ isbigfloat (x:: NumberResult ) = x. tag == BIGFLOAT
545+
546+ @inline function parsenumber (x:: LazyValue )
529547 buf = getbuf (x)
530548 pos = getpos (x)
531549 len = getlength (buf)
@@ -610,23 +628,20 @@ function applynumber(valfunc, x::LazyValue)
610628 # if we overflowed, then let's try BigFloat
611629 bres = Parsers. xparse2 (BigFloat, buf, startpos, len)
612630 if ! Parsers. invalid (bres. code)
613- valfunc (bres. val)
614- return startpos + bres. tlen
631+ return NumberResult (bres. val), startpos + bres. tlen
615632 end
616633 end
617634 if Parsers. invalid (res. code)
618635 error = InvalidNumber
619636 @goto invalid
620637 end
621- valfunc (res. val)
622- return startpos + res. tlen
638+ return NumberResult (res. val), startpos + res. tlen
623639 else
624640 if overflow
625- valfunc (isneg ? - bval : bval)
641+ return NumberResult (isneg ? - bval : bval), pos
626642 else
627- valfunc (isneg ? - val : val)
643+ return NumberResult (isneg ? - val : val), pos
628644 end
629- return pos
630645 end
631646
632647@label invalid
@@ -643,9 +658,11 @@ function skip(x::LazyValues)
643658 elseif T == JSONTypes. ARRAY
644659 return applyarray ((i, v) -> 0 , x)
645660 elseif T == JSONTypes. STRING
646- return applystring (s -> 0 , x)
661+ _, pos = parsestring (x)
662+ return pos
647663 elseif T == JSONTypes. NUMBER
648- return applynumber (n -> 0 , x)
664+ _, pos = parsenumber (x)
665+ return pos
649666 elseif T == JSONTypes. TRUE
650667 return getpos (x) + 4
651668 elseif T == JSONTypes. FALSE
@@ -716,7 +733,7 @@ function Base.show(io::IO, x::LazyValue)
716733 show (io, MIME " text/plain" (), la)
717734 end
718735 elseif T == JSONTypes. STRING
719- str, _ = applystring ( nothing , x)
736+ str, _ = parsestring ( x)
720737 Base. print (io, " JSON.LazyValue(" , repr (convert (String, str)), " )" )
721738 elseif T == JSONTypes. NULL
722739 Base. print (io, " JSON.LazyValue(nothing)" )
0 commit comments