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