package jx
import (
"github.com/go-faster/errors"
)
func (d *Decoder ) Num () (Num , error ) {
return d .num (nil , false )
}
func (d *Decoder ) NumAppend (v Num ) (Num , error ) {
return d .num (v , true )
}
func (d *Decoder ) num (v Num , forceAppend bool ) (Num , error ) {
switch d .Next () {
case String :
offset := d .offset ()
start := d .head
str , err := d .str (value {raw : true })
if err != nil {
return Num {}, errors .Wrap (err , "str" )
}
{
d := Decoder {}
d .ResetBytes (str .buf )
c , err := d .next ()
if err != nil {
return Num {}, err
}
switch c {
case '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '-' :
d .unread ()
if err := d .skipNumber (); err != nil {
return Num {}, errors .Wrap (err , "skip number" )
}
default :
return nil , badToken (c , offset )
}
}
if !str .raw || forceAppend {
v = append (v , '"' )
v = append (v , str .buf ...)
v = append (v , '"' )
return v , nil
}
return d .buf [start :d .head ], nil
case Number :
if forceAppend {
raw , err := d .RawAppend (Raw (v ))
if err != nil {
return nil , err
}
return Num (raw ), nil
}
raw , err := d .Raw ()
if err != nil {
return nil , err
}
return Num (raw ), nil
default :
return v , errors .Errorf ("unexpected %s" , d .Next ())
}
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .