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