| 165 | } |
| 166 | |
| 167 | func (dec *Decoder) skipEscapedString() error { |
| 168 | start := dec.cursor |
| 169 | for ; dec.cursor < dec.length || dec.read(); dec.cursor++ { |
| 170 | if dec.data[dec.cursor] != '\\' { |
| 171 | d := dec.data[dec.cursor] |
| 172 | dec.cursor = dec.cursor + 1 |
| 173 | nSlash := dec.cursor - start |
| 174 | switch d { |
| 175 | case '"': |
| 176 | // nSlash must be odd |
| 177 | if nSlash&1 != 1 { |
| 178 | return dec.raiseInvalidJSONErr(dec.cursor) |
| 179 | } |
| 180 | return nil |
| 181 | case 'u': // is unicode, we skip the following characters and place the cursor one one byte backward to avoid it breaking when returning to skipString |
| 182 | if err := dec.skipString(); err != nil { |
| 183 | return err |
| 184 | } |
| 185 | dec.cursor-- |
| 186 | return nil |
| 187 | case 'n', 'r', 't', '/', 'f', 'b': |
| 188 | return nil |
| 189 | default: |
| 190 | // nSlash must be even |
| 191 | if nSlash&1 == 1 { |
| 192 | return dec.raiseInvalidJSONErr(dec.cursor) |
| 193 | } |
| 194 | return nil |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | return dec.raiseInvalidJSONErr(dec.cursor) |
| 199 | } |
| 200 | |
| 201 | func (dec *Decoder) skipString() error { |
| 202 | for dec.cursor < dec.length || dec.read() { |