Added csv quoting
Build and Test API / Build-and-test-API (push) Successful in 54s Details

This commit is contained in:
Andrew Lalis 2025-02-11 20:51:26 -05:00
parent e8de8e8d59
commit ae33f57a36
1 changed files with 12 additions and 0 deletions

View File

@ -136,6 +136,18 @@ private struct CSVOutputStream(S) if (isByteOutputStream!S) {
}
void writeCell(string s) {
import std.string;
import std.regex;
import std.algorithm : canFind, any;
const pattern = ctRegex!`\"`;
if (canFind(s, "\"")) {
s = replaceAll(s, pattern, "\"\"");
}
const escapeableChars = ["\"", ",", ",", "\\", "\n"];
bool shouldQuote = escapeableChars.any!(c => canFind(s, c));
if (shouldQuote) {
s = "\"" ~ s ~ "\"";
}
writeElement(s);
}