CSV escape processing.
Build and Deploy API / build-and-deploy (push) Successful in 1m59s
Details
Build and Deploy API / build-and-deploy (push) Successful in 1m59s
Details
This commit is contained in:
parent
0f7a83dd7a
commit
44b19ed36c
|
|
@ -27,7 +27,14 @@ struct CsvStreamWriter(S) if (isByteOutputStream!S) {
|
||||||
result = stream.writeToStream([',']);
|
result = stream.writeToStream([',']);
|
||||||
throwIfError(result);
|
throwIfError(result);
|
||||||
}
|
}
|
||||||
|
import std.regex : replaceAll, regex;
|
||||||
|
import std.string : indexOf;
|
||||||
string s = value.to!string();
|
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);
|
result = stream.writeToStream(cast(ubyte[]) s);
|
||||||
throwIfError(result);
|
throwIfError(result);
|
||||||
atStartOfRow = false;
|
atStartOfRow = false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue