Deal with names with embedded quotes

This commit is contained in:
Dominic Hamon 2015-03-30 10:41:22 -07:00
parent b6e4f67d75
commit 2924aaa747

View File

@ -73,8 +73,12 @@ void CSVReporter::PrintRunData(Run const& run) {
cpu_time = cpu_time / static_cast<double>(run.iterations);
}
// Field with embedded commas must be delimited with double-quotes.
std::cout << "\"" << run.benchmark_name << "\",";
// Field with embedded double-quote characters must be doubled and the field
// delimited with double-quotes.
std::string name = run.benchmark_name;
ReplaceAll(&name, "\"", "\"\"");
std::cout << "\"" << name << "\",";
std::cout << run.iterations << ",";
std::cout << real_time << ",";
std::cout << cpu_time << ",";
@ -92,7 +96,6 @@ void CSVReporter::PrintRunData(Run const& run) {
// delimited with double-quotes.
std::string label = run.report_label;
ReplaceAll(&label, "\"", "\"\"");
std::cout << "\"" << label << "\"";
}
std::cout << '\n';