MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / scan_string

Method scan_string

Source/Utils/json.hpp:6125–6709  ·  view source on GitHub ↗

! @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

Source from the content-addressed store, hash-verified

6123 description.
6124 */
6125 token_type scan_string()
6126 {
6127 // reset token_buffer (ignore opening quote)
6128 reset();
6129
6130 // we entered the function by reading an open quote
6131 JSON_ASSERT(current == '\"');
6132
6133 while (true)
6134 {
6135 // get next character
6136 switch (get())
6137 {
6138 // end of file while parsing string
6139 case std::char_traits<char_type>::eof():
6140 {
6141 error_message = "invalid string: missing closing quote";
6142 return token_type::parse_error;
6143 }
6144
6145 // closing quote
6146 case '\"':
6147 {
6148 return token_type::value_string;
6149 }
6150
6151 // escapes
6152 case '\\':
6153 {
6154 switch (get())
6155 {
6156 // quotation mark
6157 case '\"':
6158 add('\"');
6159 break;
6160 // reverse solidus
6161 case '\\':
6162 add('\\');
6163 break;
6164 // solidus
6165 case '/':
6166 add('/');
6167 break;
6168 // backspace
6169 case 'b':
6170 add('\b');
6171 break;
6172 // form feed
6173 case 'f':
6174 add('\f');
6175 break;
6176 // line feed
6177 case 'n':
6178 add('\n');
6179 break;
6180 // carriage return
6181 case 'r':
6182 add('\r');

Callers

nothing calls this directly

Calls 3

resetFunction · 0.85
getFunction · 0.85
addFunction · 0.85

Tested by

no test coverage detected