github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/json/decode-minified-unsafe.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package json
     4  
     5  import (
     6  	"bytes"
     7  
     8  	"../convert"
     9  	"../protocol"
    10  )
    11  
    12  // DecoderUnsafeMinifed store data to decode data by each method!
    13  type DecoderUnsafeMinifed struct {
    14  	DecoderMinifed
    15  }
    16  
    17  // DecodeString return string. pass d.Buf start from after " and receive from from after "
    18  func (d *DecoderUnsafeMinifed) DecodeString() (s string, err protocol.Error) {
    19  	d.Offset(1) // due to have " at start
    20  
    21  	var loc = bytes.IndexByte(d.Buf, '"')
    22  	if loc < 0 {
    23  		err = ErrEncodedStringCorrupted
    24  		return
    25  	}
    26  
    27  	var slice []byte = d.Buf[:loc]
    28  	d.Offset(loc + 1)
    29  	s = convert.UnsafeByteSliceToString(slice)
    30  	return
    31  }