2 #ifndef COOLPROP_STRINGS_H
3 #define COOLPROP_STRINGS_H
11 #if !defined(NO_FMTLIB)
12 # ifndef FMT_HEADER_ONLY
13 # define FMT_HEADER_ONLY
15 # include "fmt/format.h"
16 # include "fmt/printf.h"
17 # undef FMT_HEADER_ONLY
25 #if !defined(__powerpc__)
29 ws = std::wstring(s.begin(), s.end());
35 #ifdef HAS_MOVE_SEMANTICS
37 inline std::string&
strlstrip(std::string& s) {
38 s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
43 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
unsigned char ch) { return !std::isspace(ch); }));
48 #ifdef HAS_MOVE_SEMANTICS
50 inline std::string&
strrstrip(std::string& s) {
51 s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
56 s.erase(std::find_if(s.rbegin(), s.rend(), [](
unsigned char ch) { return !std::isspace(ch); }).base(), s.end());
65 inline bool endswith(
const std::string& s1,
const std::string& s2) {
67 if (s2.size() > s1.size()) {
70 long lhs =
static_cast<long>(s1.rfind(s2));
71 long rhs =
static_cast<long>(s1.size()) -
static_cast<long>(s2.size());
75 #if defined(NO_FMTLIB)
77 inline std::string
format(
const char* fmt, ...);
78 #elif FMT_VERSION >= 50000
79 template <
typename... Args>
80 inline std::string
format(
const char* format_str,
const Args&... args) {
81 return fmt::sprintf(format_str, args...);
85 return fmt::sprintf(
format, args);
87 FMT_VARIADIC(std::string,
format,
const char*)
91 std::vector<std::string>
strsplit(
const std::string& s,
char del);
93 inline std::string
upper(std::string str) {
94 std::transform(str.begin(), str.end(), str.begin(), ::toupper);
98 inline std::string
lower(std::string str) {
99 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
103 std::string
strjoin(
const std::vector<std::string>& strings,
const std::string& delim);
107 return s.find(other) == 0;
119 if (mys.find(
"D") != std::string::npos) {
120 std::size_t pos = mys.find(
"D"), len = 1;
121 mys.replace(pos, len,
"e");
124 if (mys.find(
"d") != std::string::npos) {
125 std::size_t pos = mys.find(
"d"), len = 1;
126 mys.replace(pos, len,
"e");
129 const char* cs = mys.c_str();
131 double val = strtod(cs, &pEnd);
132 if ((pEnd - &(cs[0])) !=
static_cast<int>(s.size())) {