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>
|
2015-04-13 17:45:16 +00:00
|
|
|
#include "internal_macros.h"
|
2015-03-06 22:01:05 +00:00
|
|
|
|
|
|
|
namespace benchmark {
|
|
|
|
|
|
|
|
void AppendHumanReadable(int n, std::string* str);
|
|
|
|
|
2017-08-21 23:05:24 +00:00
|
|
|
std::string HumanReadableNumber(double n, double one_k = 1024.0);
|
2015-03-06 22:01:05 +00:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-04-28 08:25:29 +00:00
|
|
|
std::vector<std::string> StrSplit(const std::string& str, char delim);
|
|
|
|
|
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,
|
|
|
|
int base = 10);
|
|
|
|
int stoi(const std::string& str, size_t* pos = nullptr, int base = 10);
|
|
|
|
double stod(const std::string& str, size_t* pos = nullptr);
|
|
|
|
#else
|
|
|
|
using std::stoul;
|
|
|
|
using std::stoi;
|
|
|
|
using std::stod;
|
|
|
|
#endif
|
|
|
|
|
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_
|