CSV escape processing.
Build and Deploy API / build-and-deploy (push) Successful in 1m59s Details

This commit is contained in:
Andrew Lalis 2026-03-15 08:33:11 -04:00
parent 0f7a83dd7a
commit 44b19ed36c
1 changed files with 7 additions and 0 deletions

View File

@ -27,7 +27,14 @@ struct CsvStreamWriter(S) if (isByteOutputStream!S) {
result = stream.writeToStream([',']);
throwIfError(result);
}
import std.regex : replaceAll, regex;
import std.string : indexOf;
string s = value.to!string();
bool shouldValueBeQuoted = indexOf(s, '"') != -1 || indexOf(s, ',') != -1;
s = replaceAll(value.to!string(), regex("\""), "\"\"");
if (shouldValueBeQuoted) {
s = "\"" ~ s ~ "\"";
}
result = stream.writeToStream(cast(ubyte[]) s);
throwIfError(result);
atStartOfRow = false;