20 const auto& f = std::use_facet<std::ctype<char>>(std::locale());
21 f.toupper(s.data(), s.data() + s.size());
25static inline std::string
to_upper(std::string&& s)
41 const auto& f = std::use_facet<std::ctype<char>>(std::locale());
42 f.tolower(s.data(), s.data() + s.size());
46static inline std::string
to_lower(std::string&& s)
60static inline auto to_bool(
const std::string& s) ->
bool
64 std::stringstream(s) >> b;
65 }
else if (s.size() > 1) {
66 std::stringstream(s) >> std::boolalpha >> b;
78 const auto& loc = std::locale();
79 s.erase(s.begin(), std::find_if_not(s.begin(), s.end(), [&loc](
auto ch) {
80 return std::isspace(ch, loc);
113 const auto& loc = std::locale();
116 s.rbegin(), s.rend(),
117 [&loc](
auto ch) { return std::isspace(ch, loc); })
149static inline void trim(std::string& s)
160static inline std::string
trim(std::string&& s)
178template <
typename... Ds>
179static inline std::vector<std::string>
split(
180 const std::string& s,
const Ds&... ds)
183 std::vector<char> delims;
187 delims.emplace_back(
' ');
191 std::vector<std::string::size_type> delimPos;
192 for (
const auto& delim : delims) {
193 auto b = s.find(delim, 0);
194 while (b != std::string::npos) {
195 delimPos.emplace_back(b);
196 b = s.find(delim, b + 1);
201 std::sort(delimPos.begin(), delimPos.end());
204 std::vector<std::string> tokens;
205 std::string::size_type begin{0};
206 for (std::size_t it = 0; it < delimPos.size(); it++) {
207 auto end = delimPos[it];
208 auto t = s.substr(begin, end - begin);
210 tokens.emplace_back(t);
214 auto t = s.substr(begin);
216 tokens.emplace_back(t);
223static inline auto partition(std::string_view s, std::string_view sep)
224 -> std::tuple<std::string, std::string, std::string>
227 const auto startPos = s.find(sep);
230 if (startPos == std::string::npos) {
231 return {std::string(s),
"",
""};
235 auto pre = std::string(s.substr(0, startPos));
236 auto mid = std::string(s.substr(startPos, sep.size()));
237 auto post = std::string(s.substr(startPos + sep.size()));
240 return {pre, mid, post};
246 std::enable_if_t<std::is_integral_v<Integer>,
bool> =
true>
250 std::stringstream stream;
251 stream << std::setw(padding) << std::setfill(fill) << val;
Volume Cartographer library
static void to_lower(std::string &s)
Convert string characters to lower case (in place)
static auto to_bool(const std::string &s) -> bool
Convert a string to a bool.
static void trim_left(std::string &s)
Left trim (in place)
static void to_upper(std::string &s)
Convert string characters to upper case (in place)
static std::string to_lower_copy(std::string s)
Convert string characters to lower case (copy)
static std::string to_upper_copy(std::string s)
Convert string characters to upper case (copy)
static void trim_right(std::string &s)
Right trim (in place)
static std::string trim_left_copy(std::string s)
Left trim (copy)
auto to_padded_string(Integer val, const int padding, const char fill='0') -> std::string
Convert an Integer to a padded string.
static std::string trim_right_copy(std::string s)
Right trim (copy)
static auto partition(std::string_view s, std::string_view sep) -> std::tuple< std::string, std::string, std::string >
Partition a string by a separator substring.
static std::string trim_copy(std::string s)
Right trim (copy)
static void trim(std::string &s)
Trim from both ends (in place)
static std::vector< std::string > split(const std::string &s, const Ds &... ds)
Split a string by a delimiter.