MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / splitCStringList

Function splitCStringList

src/function/cast_from_string_functions.cpp:302–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300
301template<typename T>
302static 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
351template<typename T>
352static bool splitPossibleUnbracedList(std::string_view input, T& state, const CSVOption* option) {

Callers 2

startListCastFunction · 0.85
castMethod · 0.85

Calls 4

skipWhitespaceFunction · 0.85
skipToCloseFunction · 0.85
skipToCloseQuotesFunction · 0.85
handleValueMethod · 0.45

Tested by

no test coverage detected