! @brief scan a string literal This function scans a string according to Sect. 7 of RFC 7159. While scanning, bytes are escaped and copied into buffer token_buffer. Then the function returns successfully, token_buffer is *not* null-terminated (as it may contain \0 bytes), and token_buffer.size() is the number of bytes in the string. @return token_type::value_string if
| 6191 | description. |
| 6192 | */ |
| 6193 | token_type scan_string() |
| 6194 | { |
| 6195 | // reset token_buffer (ignore opening quote) |
| 6196 | reset(); |
| 6197 | |
| 6198 | // we entered the function by reading an open quote |
| 6199 | JSON_ASSERT(current == '\"'); |
| 6200 | |
| 6201 | while (true) |
| 6202 | { |
| 6203 | // get next character |
| 6204 | switch (get()) |
| 6205 | { |
| 6206 | // end of file while parsing string |
| 6207 | case std::char_traits<char_type>::eof(): |
| 6208 | { |
| 6209 | error_message = "invalid string: missing closing quote"; |
| 6210 | return token_type::parse_error; |
| 6211 | } |
| 6212 | |
| 6213 | // closing quote |
| 6214 | case '\"': |
| 6215 | { |
| 6216 | return token_type::value_string; |
| 6217 | } |
| 6218 | |
| 6219 | // escapes |
| 6220 | case '\\': |
| 6221 | { |
| 6222 | switch (get()) |
| 6223 | { |
| 6224 | // quotation mark |
| 6225 | case '\"': |
| 6226 | add('\"'); |
| 6227 | break; |
| 6228 | // reverse solidus |
| 6229 | case '\\': |
| 6230 | add('\\'); |
| 6231 | break; |
| 6232 | // solidus |
| 6233 | case '/': |
| 6234 | add('/'); |
| 6235 | break; |
| 6236 | // backspace |
| 6237 | case 'b': |
| 6238 | add('\b'); |
| 6239 | break; |
| 6240 | // form feed |
| 6241 | case 'f': |
| 6242 | add('\f'); |
| 6243 | break; |
| 6244 | // line feed |
| 6245 | case 'n': |
| 6246 | add('\n'); |
| 6247 | break; |
| 6248 | // carriage return |
| 6249 | case 'r': |
| 6250 | add('\r'); |