Added csv quoting
Build and Test API / Build-and-test-API (push) Successful in 54s
Details
Build and Test API / Build-and-test-API (push) Successful in 54s
Details
This commit is contained in:
parent
e8de8e8d59
commit
ae33f57a36
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue