Bump version to 19.1.0 (final)
[llvm-project.git] / third-party / benchmark / src / string_util.h
blob731aa2c04c3e0abed1e168867d91f6428a6305ef
1 #ifndef BENCHMARK_STRING_UTIL_H_
2 #define BENCHMARK_STRING_UTIL_H_
4 #include <sstream>
5 #include <string>
6 #include <utility>
7 #include <vector>
9 #include "benchmark/benchmark.h"
10 #include "benchmark/export.h"
11 #include "check.h"
12 #include "internal_macros.h"
14 namespace benchmark {
16 BENCHMARK_EXPORT
17 std::string HumanReadableNumber(double n, Counter::OneK one_k);
19 BENCHMARK_EXPORT
20 #if defined(__MINGW32__)
21 __attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2)))
22 #elif defined(__GNUC__)
23 __attribute__((format(printf, 1, 2)))
24 #endif
25 std::string
26 StrFormat(const char* format, ...);
28 inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT {
29 return out;
32 template <class First, class... Rest>
33 inline std::ostream& StrCatImp(std::ostream& out, First&& f, Rest&&... rest) {
34 out << std::forward<First>(f);
35 return StrCatImp(out, std::forward<Rest>(rest)...);
38 template <class... Args>
39 inline std::string StrCat(Args&&... args) {
40 std::ostringstream ss;
41 StrCatImp(ss, std::forward<Args>(args)...);
42 return ss.str();
45 BENCHMARK_EXPORT
46 std::vector<std::string> StrSplit(const std::string& str, char delim);
48 // Disable lint checking for this block since it re-implements C functions.
49 // NOLINTBEGIN
50 #ifdef BENCHMARK_STL_ANDROID_GNUSTL
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.
57 unsigned long stoul(const std::string& str, size_t* pos = nullptr,
58 int base = 10);
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
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)
65 #endif
66 // NOLINTEND
68 } // end namespace benchmark
70 #endif // BENCHMARK_STRING_UTIL_H_