...

Source file src/github.com/json-iterator/go/iter_skip_strict.go

Documentation: github.com/json-iterator/go

     1  //+build !jsoniter_sloppy
     2  
     3  package jsoniter
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  )
     9  
    10  func (iter *Iterator) skipNumber() {
    11  	if !iter.trySkipNumber() {
    12  		iter.unreadByte()
    13  		if iter.Error != nil && iter.Error != io.EOF {
    14  			return
    15  		}
    16  		iter.ReadFloat64()
    17  		if iter.Error != nil && iter.Error != io.EOF {
    18  			iter.Error = nil
    19  			iter.ReadBigFloat()
    20  		}
    21  	}
    22  }
    23  
    24  func (iter *Iterator) trySkipNumber() bool {
    25  	dotFound := false
    26  	for i := iter.head; i < iter.tail; i++ {
    27  		c := iter.buf[i]
    28  		switch c {
    29  		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
    30  		case '.':
    31  			if dotFound {
    32  				iter.ReportError("validateNumber", `more than one dot found in number`)
    33  				return true // already failed
    34  			}
    35  			if i+1 == iter.tail {
    36  				return false
    37  			}
    38  			c = iter.buf[i+1]
    39  			switch c {
    40  			case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
    41  			default:
    42  				iter.ReportError("validateNumber", `missing digit after dot`)
    43  				return true // already failed
    44  			}
    45  			dotFound = true
    46  		default:
    47  			switch c {
    48  			case ',', ']', '}', ' ', '\t', '\n', '\r':
    49  				if iter.head == i {
    50  					return false // if - without following digits
    51  				}
    52  				iter.head = i
    53  				return true // must be valid
    54  			}
    55  			return false // may be invalid
    56  		}
    57  	}
    58  	return false
    59  }
    60  
    61  func (iter *Iterator) skipString() {
    62  	if !iter.trySkipString() {
    63  		iter.unreadByte()
    64  		iter.ReadString()
    65  	}
    66  }
    67  
    68  func (iter *Iterator) trySkipString() bool {
    69  	for i := iter.head; i < iter.tail; i++ {
    70  		c := iter.buf[i]
    71  		if c == '"' {
    72  			iter.head = i + 1
    73  			return true // valid
    74  		} else if c == '\\' {
    75  			return false
    76  		} else if c < ' ' {
    77  			iter.ReportError("trySkipString",
    78  				fmt.Sprintf(`invalid control character found: %d`, c))
    79  			return true // already failed
    80  		}
    81  	}
    82  	return false
    83  }
    84  
    85  func (iter *Iterator) skipObject() {
    86  	iter.unreadByte()
    87  	iter.ReadObjectCB(func(iter *Iterator, field string) bool {
    88  		iter.Skip()
    89  		return true
    90  	})
    91  }
    92  
    93  func (iter *Iterator) skipArray() {
    94  	iter.unreadByte()
    95  	iter.ReadArrayCB(func(iter *Iterator) bool {
    96  		iter.Skip()
    97  		return true
    98  	})
    99  }
   100  

View as plain text