Eric Fiselier | 60e26b7 | 2015-03-09 16:18:10 -0400 | [diff] [blame] | 1 | #ifndef BENCHMARK_STRING_UTIL_H_ |
| 2 | #define BENCHMARK_STRING_UTIL_H_ |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 3 | |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 4 | #include <sstream> |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 5 | #include <string> |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 6 | #include <utility> |
Dominic Hamon | 974cd5a | 2022-08-04 15:33:35 +0100 | [diff] [blame] | 7 | #include <vector> |
Dominic Hamon | fcef4fb | 2021-11-10 16:04:32 +0000 | [diff] [blame] | 8 | |
dominic | b1c4a75 | 2023-07-14 13:56:01 +0100 | [diff] [blame] | 9 | #include "benchmark/benchmark.h" |
Sergiu Deitsch | 9e47d07 | 2022-02-14 11:48:53 +0100 | [diff] [blame] | 10 | #include "benchmark/export.h" |
Dominic Hamon | 974cd5a | 2022-08-04 15:33:35 +0100 | [diff] [blame] | 11 | #include "check.h" |
Jean-Louis Leroy | d49516b | 2015-04-13 13:45:16 -0400 | [diff] [blame] | 12 | #include "internal_macros.h" |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 13 | |
| 14 | namespace benchmark { |
| 15 | |
dominic | b1c4a75 | 2023-07-14 13:56:01 +0100 | [diff] [blame] | 16 | BENCHMARK_EXPORT |
dominic | b1c4a75 | 2023-07-14 13:56:01 +0100 | [diff] [blame] | 17 | std::string HumanReadableNumber(double n, Counter::OneK one_k); |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 18 | |
Sergiu Deitsch | 9e47d07 | 2022-02-14 11:48:53 +0100 | [diff] [blame] | 19 | BENCHMARK_EXPORT |
Daniel Harvey | e366656 | 2019-03-26 11:50:53 +0100 | [diff] [blame] | 20 | #if defined(__MINGW32__) |
| 21 | __attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2))) |
| 22 | #elif defined(__GNUC__) |
Roman Lebedev | c9f2693 | 2018-11-27 03:55:05 +0300 | [diff] [blame] | 23 | __attribute__((format(printf, 1, 2))) |
| 24 | #endif |
| 25 | std::string |
| 26 | StrFormat(const char* format, ...); |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 27 | |
Wink Saville | 6149723 | 2018-03-07 03:20:06 -0800 | [diff] [blame] | 28 | inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT { |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 29 | return out; |
| 30 | } |
| 31 | |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 32 | template <class First, class... Rest> |
BaaMeow | 4c2af07 | 2018-06-01 06:14:19 -0400 | [diff] [blame] | 33 | inline std::ostream& StrCatImp(std::ostream& out, First&& f, Rest&&... rest) { |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 34 | out << std::forward<First>(f); |
Wink Saville | 6149723 | 2018-03-07 03:20:06 -0800 | [diff] [blame] | 35 | return StrCatImp(out, std::forward<Rest>(rest)...); |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 38 | template <class... Args> |
| 39 | inline std::string StrCat(Args&&... args) { |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 40 | std::ostringstream ss; |
Wink Saville | 6149723 | 2018-03-07 03:20:06 -0800 | [diff] [blame] | 41 | StrCatImp(ss, std::forward<Args>(args)...); |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 42 | return ss.str(); |
| 43 | } |
| 44 | |
Sergiu Deitsch | 9e47d07 | 2022-02-14 11:48:53 +0100 | [diff] [blame] | 45 | BENCHMARK_EXPORT |
Mircea Trofin | 376ebc2 | 2021-04-28 01:25:29 -0700 | [diff] [blame] | 46 | std::vector<std::string> StrSplit(const std::string& str, char delim); |
| 47 | |
Vy Nguyen | 8722d6f | 2021-11-17 12:57:36 -0500 | [diff] [blame] | 48 | // Disable lint checking for this block since it re-implements C functions. |
| 49 | // NOLINTBEGIN |
Marat Dukhan | 7fb3c56 | 2018-06-05 03:36:26 -0700 | [diff] [blame] | 50 | #ifdef BENCHMARK_STL_ANDROID_GNUSTL |
| 51 | /* |
| 52 | * GNU STL in Android NDK lacks support for some C++11 functions, including |
| 53 | * stoul, stoi, stod. We reimplement them here using C functions strtoul, |
| 54 | * strtol, strtod. Note that reimplemented functions are in benchmark:: |
| 55 | * namespace, not std:: namespace. |
| 56 | */ |
| 57 | unsigned long stoul(const std::string& str, size_t* pos = nullptr, |
Dominic Hamon | fcef4fb | 2021-11-10 16:04:32 +0000 | [diff] [blame] | 58 | int base = 10); |
Marat Dukhan | 7fb3c56 | 2018-06-05 03:36:26 -0700 | [diff] [blame] | 59 | int stoi(const std::string& str, size_t* pos = nullptr, int base = 10); |
| 60 | double stod(const std::string& str, size_t* pos = nullptr); |
| 61 | #else |
Vy Nguyen | 91ed7ee | 2021-11-19 06:12:59 -0500 | [diff] [blame] | 62 | using std::stod; // NOLINT(misc-unused-using-decls) |
| 63 | using std::stoi; // NOLINT(misc-unused-using-decls) |
| 64 | using std::stoul; // NOLINT(misc-unused-using-decls) |
Marat Dukhan | 7fb3c56 | 2018-06-05 03:36:26 -0700 | [diff] [blame] | 65 | #endif |
Vy Nguyen | 8722d6f | 2021-11-17 12:57:36 -0500 | [diff] [blame] | 66 | // NOLINTEND |
Marat Dukhan | 7fb3c56 | 2018-06-05 03:36:26 -0700 | [diff] [blame] | 67 | |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 68 | } // end namespace benchmark |
Eric Fiselier | a187aa0 | 2015-03-06 17:01:05 -0500 | [diff] [blame] | 69 | |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 70 | #endif // BENCHMARK_STRING_UTIL_H_ |