From 2924aaa747cbf737d448dc67ba6ec32c50cf5a13 Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Mon, 30 Mar 2015 10:41:22 -0700 Subject: [PATCH] Deal with names with embedded quotes --- src/csv_reporter.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/csv_reporter.cc b/src/csv_reporter.cc index 08dad199..4d4e5694 100644 --- a/src/csv_reporter.cc +++ b/src/csv_reporter.cc @@ -73,8 +73,12 @@ void CSVReporter::PrintRunData(Run const& run) { cpu_time = cpu_time / static_cast(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';