/////////////////////////////////////////////////////////////////////////// Full implementation of a quoted word. Includes: '\'' '"' "'" "\"" 'one two' Result includes the quotes.
| 1186 | // 'one two' |
| 1187 | // Result includes the quotes. |
| 1188 | bool Lexer::readWord(const std::string& text, const std::string& quotes, |
| 1189 | std::string::size_type& cursor, std::string& word) { |
| 1190 | if (quotes.find(text[cursor]) == std::string::npos) return false; |
| 1191 | |
| 1192 | std::string::size_type eos = text.length(); |
| 1193 | int quote = text[cursor++]; |
| 1194 | word = quote; |
| 1195 | |
| 1196 | int c; |
| 1197 | while ((c = text[cursor])) { |
| 1198 | // Quoted word ends on a quote. |
| 1199 | if (quote && quote == c) { |
| 1200 | word += utf8_character(utf8_next_char(text, cursor)); |
| 1201 | break; |
| 1202 | } |
| 1203 | |
| 1204 | // Unicode U+XXXX or \uXXXX codepoint. |
| 1205 | else if (eos - cursor >= 6 && |
| 1206 | ((text[cursor + 0] == 'U' && text[cursor + 1] == '+') || |
| 1207 | (text[cursor + 0] == '\\' && text[cursor + 1] == 'u')) && |
| 1208 | unicodeHexDigit(text[cursor + 2]) && unicodeHexDigit(text[cursor + 3]) && |
| 1209 | unicodeHexDigit(text[cursor + 4]) && unicodeHexDigit(text[cursor + 5])) { |
| 1210 | word += utf8_character( |
| 1211 | hexToInt(text[cursor + 2], text[cursor + 3], text[cursor + 4], text[cursor + 5])); |
| 1212 | cursor += 6; |
| 1213 | } |
| 1214 | |
| 1215 | // An escaped thing. |
| 1216 | else if (c == '\\') { |
| 1217 | c = text[++cursor]; |
| 1218 | |
| 1219 | switch (c) { |
| 1220 | case '"': |
| 1221 | word += (char)0x22; |
| 1222 | ++cursor; |
| 1223 | break; |
| 1224 | case '\'': |
| 1225 | word += (char)0x27; |
| 1226 | ++cursor; |
| 1227 | break; |
| 1228 | case '\\': |
| 1229 | word += (char)0x5C; |
| 1230 | ++cursor; |
| 1231 | break; |
| 1232 | case 'b': |
| 1233 | word += (char)0x08; |
| 1234 | ++cursor; |
| 1235 | break; |
| 1236 | case 'f': |
| 1237 | word += (char)0x0C; |
| 1238 | ++cursor; |
| 1239 | break; |
| 1240 | case 'n': |
| 1241 | word += (char)0x0A; |
| 1242 | ++cursor; |
| 1243 | break; |
| 1244 | case 'r': |
| 1245 | word += (char)0x0D; |