| 300 | |
| 301 | template<typename T> |
| 302 | static bool splitCStringList(const char* input, uint64_t len, T& state, const CSVOption* option) { |
| 303 | auto end = input + len; |
| 304 | uint64_t lvl = 1; |
| 305 | bool seenValue = false; |
| 306 | |
| 307 | // locate [ |
| 308 | skipWhitespace(input, end); |
| 309 | if (input == end || *input != CopyConstants::DEFAULT_CSV_LIST_BEGIN_CHAR) { |
| 310 | return false; |
| 311 | } |
| 312 | skipWhitespace(++input, end); |
| 313 | |
| 314 | bool justFinishedEntry = true; // true at start |
| 315 | auto startPtr = input; |
| 316 | while (input < end) { |
| 317 | auto ch = *input; |
| 318 | if (ch == CopyConstants::DEFAULT_CSV_LIST_BEGIN_CHAR) { |
| 319 | if (!skipToClose(input, end, ++lvl, CopyConstants::DEFAULT_CSV_LIST_END_CHAR, option)) { |
| 320 | return false; |
| 321 | } |
| 322 | } else if ((ch == '\'' || ch == '"') && justFinishedEntry) { |
| 323 | const char* prevInput = input; |
| 324 | if (!skipToCloseQuotes(input, end)) { |
| 325 | input = prevInput; |
| 326 | } |
| 327 | } else if (ch == '{') { |
| 328 | uint64_t struct_lvl = 0; |
| 329 | skipToClose(input, end, struct_lvl, '}', option); |
| 330 | } else if (ch == ',' || ch == CopyConstants::DEFAULT_CSV_LIST_END_CHAR) { // split |
| 331 | if (ch != CopyConstants::DEFAULT_CSV_LIST_END_CHAR || startPtr < input || seenValue) { |
| 332 | state.handleValue(startPtr, input, option); |
| 333 | seenValue = true; |
| 334 | } |
| 335 | if (ch == CopyConstants::DEFAULT_CSV_LIST_END_CHAR) { // last ] |
| 336 | lvl--; |
| 337 | break; |
| 338 | } |
| 339 | skipWhitespace(++input, end); |
| 340 | startPtr = input; |
| 341 | justFinishedEntry = true; |
| 342 | continue; |
| 343 | } |
| 344 | justFinishedEntry = false; |
| 345 | input++; |
| 346 | } |
| 347 | skipWhitespace(++input, end); |
| 348 | return (input == end && lvl == 0); |
| 349 | } |
| 350 | |
| 351 | template<typename T> |
| 352 | static bool splitPossibleUnbracedList(std::string_view input, T& state, const CSVOption* option) { |
no test coverage detected