2015-03-09 20:18:10 +00:00
|
|
|
#ifndef BENCHMARK_STRING_UTIL_H_
|
|
|
|
#define BENCHMARK_STRING_UTIL_H_
|
2015-03-06 22:01:05 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
2016-10-07 18:35:03 +00:00
|
|
|
#include <string>
|
2015-03-06 22:01:05 +00:00
|
|
|
#include <utility>
|
2022-08-04 14:33:35 +00:00
|
|
|
#include <vector>
|
2021-11-10 16:04:32 +00:00
|
|
|
|
2023-07-14 12:56:01 +00:00
|
|
|
#include "benchmark/benchmark.h"
|
2022-02-14 10:48:53 +00:00
|
|
|
#include "benchmark/export.h"
|
2022-08-04 14:33:35 +00:00
|
|
|
#include "check.h"
|
2015-04-13 17:45:16 +00:00
|
|
|
#include "internal_macros.h"
|
2015-03-06 22:01:05 +00:00
|
|
|
|
|
|
|
namespace benchmark {
|
|
|
|
|
2023-07-14 12:56:01 +00:00
|
|
|
BENCHMARK_EXPORT
|
|
|
|
std::string HumanReadableNumber(double n, Counter::OneK one_k);
|
2015-03-06 22:01:05 +00:00
|
|
|
|
2022-02-14 10:48:53 +00:00
|
|
|
BENCHMARK_EXPORT
|
2019-03-26 10:50:53 +00:00
|
|
|
#if defined(__MINGW32__)
|
|
|
|
__attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2)))
|
|
|
|
#elif defined(__GNUC__)
|
2018-11-27 00:55:05 +00:00
|
|
|
__attribute__((format(printf, 1, 2)))
|
|
|
|
#endif
|
|
|
|
std::string
|
|
|
|
StrFormat(const char* format, ...);
|
2015-03-06 22:01:05 +00:00
|
|
|
|
2018-03-07 11:20:06 +00:00
|
|
|
inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT {
|
2015-03-06 22:01:05 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-10-07 18:35:03 +00:00
|
|
|
template <class First, class... Rest>
|
2018-06-01 10:14:19 +00:00
|
|
|
inline std::ostream& StrCatImp(std::ostream& out, First&& f, Rest&&... rest) {
|
2015-03-06 22:01:05 +00:00
|
|
|
out << std::forward<First>(f);
|
2018-03-07 11:20:06 +00:00
|
|
|
return StrCatImp(out, std::forward<Rest>(rest)...);
|
2015-03-06 22:01:05 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 18:35:03 +00:00
|
|
|
template <class... Args>
|
|
|
|
inline std::string StrCat(Args&&... args) {
|
2015-03-06 22:01:05 +00:00
|
|
|
std::ostringstream ss;
|
2018-03-07 11:20:06 +00:00
|
|
|
StrCatImp(ss, std::forward<Args>(args)...);
|
2015-03-06 22:01:05 +00:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2022-02-14 10:48:53 +00:00
|
|
|
BENCHMARK_EXPORT
|
2021-04-28 08:25:29 +00:00
|
|
|
std::vector<std::string> StrSplit(const std::string& str, char delim);
|
|
|
|
|
2021-11-17 17:57:36 +00:00
|
|
|
// Disable lint checking for this block since it re-implements C functions.
|
|
|
|
// NOLINTBEGIN
|
2018-06-05 10:36:26 +00:00
|
|
|
#ifdef BENCHMARK_STL_ANDROID_GNUSTL
|
|
|
|
/*
|
|
|
|
* GNU STL in Android NDK lacks support for some C++11 functions, including
|
|
|
|
* stoul, stoi, stod. We reimplement them here using C functions strtoul,
|
|
|
|
* strtol, strtod. Note that reimplemented functions are in benchmark::
|
|
|
|
* namespace, not std:: namespace.
|
|
|
|
*/
|
|
|
|
unsigned long stoul(const std::string& str, size_t* pos = nullptr,
|
2021-11-10 16:04:32 +00:00
|
|
|
int base = 10);
|
2018-06-05 10:36:26 +00:00
|
|
|
int stoi(const std::string& str, size_t* pos = nullptr, int base = 10);
|
|
|
|
double stod(const std::string& str, size_t* pos = nullptr);
|
|
|
|
#else
|
2021-11-19 11:12:59 +00:00
|
|
|
using std::stod; // NOLINT(misc-unused-using-decls)
|
|
|
|
using std::stoi; // NOLINT(misc-unused-using-decls)
|
|
|
|
using std::stoul; // NOLINT(misc-unused-using-decls)
|
2018-06-05 10:36:26 +00:00
|
|
|
#endif
|
2021-11-17 17:57:36 +00:00
|
|
|
// NOLINTEND
|
2018-06-05 10:36:26 +00:00
|
|
|
|
2016-10-07 18:35:03 +00:00
|
|
|
} // end namespace benchmark
|
2015-03-06 22:01:05 +00:00
|
|
|
|
2016-10-07 18:35:03 +00:00
|
|
|
#endif // BENCHMARK_STRING_UTIL_H_
|