| 1054 | } |
| 1055 | |
| 1056 | std::string escapeCsvString(const std::string& field, const std::string& delimiter) { |
| 1057 | bool needsQuoting = |
| 1058 | field.find_first_of("\"" + delimiter + "\n") != std::string::npos || field.empty(); |
| 1059 | if (!needsQuoting) { |
| 1060 | return field; |
| 1061 | } |
| 1062 | |
| 1063 | std::ostringstream quotedField; |
| 1064 | quotedField << '"'; |
| 1065 | for (char c : field) { |
| 1066 | if (c == '"') { |
| 1067 | quotedField << "\"\""; |
| 1068 | } else { |
| 1069 | quotedField << c; |
| 1070 | } |
| 1071 | } |
| 1072 | quotedField << '"'; |
| 1073 | return quotedField.str(); |
| 1074 | } |
| 1075 | |
| 1076 | // TODO(Ziyi): Move the printing logic under each printer and each printer should expose a unified |
| 1077 | // `print` interface. |
no test coverage detected