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
9namespace benchmark {
10
11void AppendHumanReadable(int n, std::string* str);
12
13std::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
20std::string
21StrFormat(const char* format, ...);
22
23inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT {
24 return out;
25}
26
27template <class First, class... Rest>
28inline 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
33template <class... Args>
34inline std::string StrCat(Args&&... args) {
35 std::ostringstream ss;
36 StrCatImp(ss, std::forward<Args>(args)...);
37 return ss.str();
38}
39
40#ifdef BENCHMARK_STL_ANDROID_GNUSTL
41/*
42 * GNU STL in Android NDK lacks support for some C++11 functions, including
43 * stoul, stoi, stod. We reimplement them here using C functions strtoul,
44 * strtol, strtod. Note that reimplemented functions are in benchmark::
45 * namespace, not std:: namespace.
46 */
47unsigned long stoul(const std::string& str, size_t* pos = nullptr,
48 int base = 10);
49int stoi(const std::string& str, size_t* pos = nullptr, int base = 10);
50double stod(const std::string& str, size_t* pos = nullptr);
51#else
52using std::stoul;
53using std::stoi;
54using std::stod;
55#endif
56
57} // end namespace benchmark
58
59#endif // BENCHMARK_STRING_UTIL_H_
60