mirror of
https://github.com/google/benchmark.git
synced 2025-01-14 22:00:33 +08:00
Add double-quotes where necessary
This commit is contained in:
parent
71c41cde57
commit
680a399a93
@ -22,6 +22,8 @@
|
||||
#include "string_util.h"
|
||||
#include "walltime.h"
|
||||
|
||||
// File format reference: http://edoceo.com/utilitas/csv-file-format.
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
bool CSVReporter::ReportContext(const Context& context) {
|
||||
@ -71,7 +73,8 @@ void CSVReporter::PrintRunData(Run const& run) {
|
||||
cpu_time = cpu_time / static_cast<double>(run.iterations);
|
||||
}
|
||||
|
||||
std::cout << run.benchmark_name << ",";
|
||||
// Field with embedded commas must be delimited with double-quotes.
|
||||
std::cout << "\"" << run.benchmark_name << "\",";
|
||||
std::cout << run.iterations << ",";
|
||||
std::cout << real_time << ",";
|
||||
std::cout << cpu_time << ",";
|
||||
@ -85,7 +88,12 @@ void CSVReporter::PrintRunData(Run const& run) {
|
||||
}
|
||||
std::cout << ",";
|
||||
if (!run.report_label.empty()) {
|
||||
std::cout << run.report_label;
|
||||
// Field with embedded double-quote characters must be doubled and the field
|
||||
// delimited with double-quotes.
|
||||
std::string label = run.report_label;
|
||||
ReplaceAll(&label, "\"", "\"\"");
|
||||
|
||||
std::cout << "\"" << label << "\"";
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
@ -154,4 +154,13 @@ std::string StringPrintF(const char* format, ...)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void ReplaceAll(std::string* str, const std::string& from,
|
||||
const std::string& to) {
|
||||
std::size_t start = 0;
|
||||
while((start = str->find(from, start)) != std::string::npos) {
|
||||
str->replace(start, from.length(), to);
|
||||
start += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace benchmark
|
||||
|
@ -35,6 +35,9 @@ inline std::string StrCat(Args&&... args)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void ReplaceAll(std::string* str, const std::string& from,
|
||||
const std::string& to);
|
||||
|
||||
} // end namespace benchmark
|
||||
|
||||
#endif // BENCHMARK_STRING_UTIL_H_
|
||||
|
Loading…
Reference in New Issue
Block a user