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

     1  package jzon
     2  
     3  func skipObjectWithStack(it *Iterator, _ byte) error {
     4  	c, err := it.nextToken()
     5  	if err != nil {
     6  		return err
     7  	}
     8  	if c == '}' {
     9  		it.head++
    10  		return nil
    11  	}
    12  	for {
    13  		if c != '"' {
    14  			return UnexpectedByteError{got: c, exp: '"'}
    15  		}
    16  		it.head++
    17  		if err = it.skipObjectField(); err != nil {
    18  			return err
    19  		}
    20  		c, err = it.nextToken()
    21  		if err != nil {
    22  			return err
    23  		}
    24  		it.head++
    25  		switch c {
    26  		case '{':
    27  			s := stackPool.Get().(*stack).initObject()
    28  			err := skipWithStack(it, stackElementObjectBegin, s)
    29  			stackPool.Put(s)
    30  			return err
    31  		case '[':
    32  			s := stackPool.Get().(*stack).initObject()
    33  			err := skipWithStack(it, stackElementArrayBegin, s)
    34  			stackPool.Put(s)
    35  			return err
    36  		}
    37  		if err = skipFunctions[c](it, c); err != nil {
    38  			return err
    39  		}
    40  		c, err = it.nextToken()
    41  		if err != nil {
    42  			return err
    43  		}
    44  		it.head++
    45  		if c == '}' {
    46  			return nil
    47  		}
    48  		if c != ',' {
    49  			return UnexpectedByteError{got: c, exp: '}', exp2: ','}
    50  		}
    51  		c, err = it.nextToken()
    52  		if err != nil {
    53  			return err
    54  		}
    55  	}
    56  }
    57  
    58  // SkipObject skips an object
    59  func (it *Iterator) SkipObject() error {
    60  	c, err := it.nextToken()
    61  	if err != nil {
    62  		return err
    63  	}
    64  	if c != '{' {
    65  		return UnexpectedByteError{got: c, exp: '{'}
    66  	}
    67  	it.head++
    68  	return skipObjectWithStack(it, c)
    69  }