---------------------------------------------------------------------- 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
| 39 | // Example: [some "string" to test] --> [some ""string"" to test] |
| 40 | // ---------------------------------------------------------------------- |
| 41 | int 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() |
no outgoing calls
no test coverage detected