MCPcopy Create free account
hub / github.com/apache/impala / EscapeStrForCSV

Function EscapeStrForCSV

be/src/gutil/strings/escaping.cc:41–58  ·  view source on GitHub ↗

---------------------------------------------------------------------- EscapeStrForCSV() Escapes the quotes in 'src' by doubling them. This is necessary for generating CSV files (see SplitCSVLine). Returns the number of characters written into dest (not counting the \0) or -1 if there was insufficient space. Dest could end up twice as long as src. Example: [some "string" to test] --> [some ""stri

Source from the content-addressed store, hash-verified

39// Example: [some "string" to test] --> [some ""string"" to test]
40// ----------------------------------------------------------------------
41int EscapeStrForCSV(const char* src, char* dest, int dest_len) {
42 int used = 0;
43
44 while (true) {
45 if (*src == '\0' && used < dest_len) {
46 dest[used] = '\0';
47 return used;
48 }
49
50 if (used + 1 >= dest_len) // +1 because we might require two characters
51 return -1;
52
53 if (*src == '"')
54 dest[used++] = '"';
55
56 dest[used++] = *src++;
57 }
58}
59
60// ----------------------------------------------------------------------
61// UnescapeCEscapeSequences()

Callers 1

JoinCSVLineWithDelimiterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected