MCPcopy Create free account
hub / github.com/francoispqt/gojay / skipArray

Method skipArray

decode_array.go:139–190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

137}
138
139func (dec *Decoder) skipArray() (int, error) {
140 var arraysOpen = 1
141 var arraysClosed = 0
142 // var stringOpen byte = 0
143 for j := dec.cursor; j < dec.length || dec.read(); j++ {
144 switch dec.data[j] {
145 case ']':
146 arraysClosed++
147 // everything is closed return
148 if arraysOpen == arraysClosed {
149 // add char to object data
150 return j + 1, nil
151 }
152 case '[':
153 arraysOpen++
154 case '"':
155 j++
156 var isInEscapeSeq bool
157 var isFirstQuote = true
158 for ; j < dec.length || dec.read(); j++ {
159 if dec.data[j] != '"' {
160 continue
161 }
162 if dec.data[j-1] != '\\' || (!isInEscapeSeq && !isFirstQuote) {
163 break
164 } else {
165 isInEscapeSeq = false
166 }
167 if isFirstQuote {
168 isFirstQuote = false
169 }
170 // loop backward and count how many anti slash found
171 // to see if string is effectively escaped
172 ct := 0
173 for i := j - 1; i > 0; i-- {
174 if dec.data[i] != '\\' {
175 break
176 }
177 ct++
178 }
179 // is pair number of slashes, quote is not escaped
180 if ct&1 == 0 {
181 break
182 }
183 isInEscapeSeq = true
184 }
185 default:
186 continue
187 }
188 }
189 return 0, dec.raiseInvalidJSONErr(dec.cursor)
190}
191
192// DecodeArrayFunc is a func type implementing UnmarshalerJSONArray.
193// Use it to cast a `func(*Decoder) error` to Unmarshal an array on the fly.

Callers 5

TestSkipArrayFunction · 0.95
decodeEmbeddedJSONMethod · 0.95
getObjectMethod · 0.95
skipDataMethod · 0.95
TestSkipDataFunction · 0.95

Calls 2

readMethod · 0.95
raiseInvalidJSONErrMethod · 0.95

Tested by 2

TestSkipArrayFunction · 0.76
TestSkipDataFunction · 0.76