benchmark  1.9.4
string_util.h
1 #ifndef BENCHMARK_STRING_UTIL_H_
2 #define BENCHMARK_STRING_UTIL_H_
3 
4 #include <sstream>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 #include "benchmark/benchmark.h"
10 #include "benchmark/export.h"
11 #include "check.h"
12 
13 namespace benchmark {
14 
15 BENCHMARK_EXPORT
16 std::string HumanReadableNumber(double n, Counter::OneK one_k);
17 
18 BENCHMARK_EXPORT
19 #if defined(__MINGW32__)
20 __attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2)))
21 #elif defined(__GNUC__)
22 __attribute__((format(printf, 1, 2)))
23 #endif
24 std::string
25 StrFormat(const char* format, ...);
26 
27 inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT {
28  return out;
29 }
30 
31 template <class First, class... Rest>
32 inline std::ostream& StrCatImp(std::ostream& out, First&& f, Rest&&... rest) {
33  out << std::forward<First>(f);
34  return StrCatImp(out, std::forward<Rest>(rest)...);
35 }
36 
37 template <class... Args>
38 inline std::string StrCat(Args&&... args) {
39  std::ostringstream ss;
40  StrCatImp(ss, std::forward<Args>(args)...);
41  return ss.str();
42 }
43 
44 BENCHMARK_EXPORT
45 std::vector<std::string> StrSplit(const std::string& str, char delim);
46 
47 // Disable lint checking for this block since it re-implements C functions.
48 // NOLINTBEGIN
49 #ifdef BENCHMARK_STL_ANDROID_GNUSTL
50 /*
51  * GNU STL in Android NDK lacks support for some C++11 functions, including
52  * stoul, stoi, stod. We reimplement them here using C functions strtoul,
53  * strtol, strtod. Note that reimplemented functions are in benchmark::
54  * namespace, not std:: namespace.
55  */
56 unsigned long stoul(const std::string& str, size_t* pos = nullptr,
57  int base = 10);
58 int stoi(const std::string& str, size_t* pos = nullptr, int base = 10);
59 double stod(const std::string& str, size_t* pos = nullptr);
60 #else
61 using std::stod; // NOLINT(misc-unused-using-decls)
62 using std::stoi; // NOLINT(misc-unused-using-decls)
63 using std::stoul; // NOLINT(misc-unused-using-decls)
64 #endif
65 // NOLINTEND
66 
67 } // end namespace benchmark
68 
69 #endif // BENCHMARK_STRING_UTIL_H_