github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_number.go (about)

     1  package jzon
     2  
     3  // it.head has already be forwarded before calling this
     4  func (it *Iterator) readNumberAsString(c byte) (n string, err error) {
     5  	// start capture
     6  	oldCapture := it.capture
     7  	it.capture = true
     8  
     9  	// save current location
    10  	// this should be a safe operation because the c is still in the buffer
    11  	begin := it.head - 1
    12  	err = skipNumber(it, c)
    13  	if err == nil {
    14  		n = string(it.buffer[begin:it.head])
    15  	}
    16  	// end capture
    17  	it.capture = oldCapture
    18  	return
    19  }
    20  
    21  // ReadNumber reads a Number(json.Number)
    22  func (it *Iterator) ReadNumber() (n Number, err error) {
    23  	c, err := it.nextToken()
    24  	if err != nil {
    25  		return
    26  	}
    27  	if valueTypeMap[c] != NumberValue {
    28  		err = UnexpectedByteError{got: c}
    29  		return
    30  	}
    31  	it.head++
    32  	s, err := it.readNumberAsString(c)
    33  	return Number(s), err
    34  }