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