benchmark
1.10.0
Toggle main menu visibility
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
13
namespace
benchmark {
14
15
BENCHMARK_EXPORT
16
std::string HumanReadableNumber(
double
n, Counter::OneK one_k,
17
bool
stringify_exponent =
false
);
18
19
BENCHMARK_EXPORT
20
std::string StrFormat(
const
char
* format, ...) PRINTF_FORMAT_STRING_FUNC(1, 2);
21
22
inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT {
23
return
out;
24
}
25
26
template
<
class
First,
class
... Rest>
27
inline
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
32
template
<
class
... Args>
33
inline
std::string StrCat(Args&&... args) {
34
std::ostringstream ss;
35
StrCatImp(ss, std::forward<Args>(args)...);
36
return
ss.str();
37
}
38
39
BENCHMARK_EXPORT
40
std::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
*/
51
unsigned
long
stoul(
const
std::string& str,
size_t
* pos =
nullptr
,
52
int
base = 10);
53
int
stoi(
const
std::string& str,
size_t
* pos =
nullptr
,
int
base = 10);
54
double
stod(
const
std::string& str,
size_t
* pos =
nullptr
);
55
#else
56
using
std::stod;
// NOLINT(misc-unused-using-decls)
57
using
std::stoi;
// NOLINT(misc-unused-using-decls)
58
using
std::stoul;
// NOLINT(misc-unused-using-decls)
59
#endif
60
// NOLINTEND
61
62
}
// end namespace benchmark
63
64
#endif
// BENCHMARK_STRING_UTIL_H_
src
string_util.h
Generated by
1.18.0