12#ifndef SST_CORE_STRINGIZE_H
13#define SST_CORE_STRINGIZE_H
26strcasecmp(
const std::string& s1,
const std::string& s2)
28 return !::strcasecmp(s1.c_str(), s2.c_str());
32to_lower(std::string& s)
34 for (
size_t i = 0; i < s.size(); i++ ) {
35 s[i] = std::tolower(s[i]);
42 auto start = s.find_first_not_of(
" \t\n\r\v\f");
44 s.replace(s.begin(), s.begin() + (start),
"");
46 auto end = s.find_last_not_of(
" \t\n\r\v\f");
47 if ( end != s.size() - 1 ) {
48 s.replace(s.begin() + end + 1, s.end(),
"");
53tokenize(std::vector<std::string>& output,
const std::string& input,
const std::string& delim,
bool trim_ws =
false)
56 size_t end = input.find(delim);
59 while ( end != std::string::npos ) {
60 token = input.substr(start, end - start);
61 if ( trim_ws ) trim(token);
62 output.push_back(token);
63 start = end + delim.length();
64 end = input.find(delim, start);
67 token = input.substr(start, end);
68 if ( trim_ws ) trim(token);
69 output.push_back(token);
74 using iter = std::string::const_iterator;
75 const std::string delim;
76 explicit char_delimiter(
const std::string& delim =
" \t\v\f\n\r") :
83 void operator()(iter& first, iter last, std::string& token)
88 while ( first != last && delim.find(*first) != std::string::npos )
91 while ( first != last && delim.find(*first) == std::string::npos )
96struct escaped_list_separator
98 using iter = std::string::const_iterator;
101 escaped_list_separator(
102 const std::string& esc =
"\\",
const std::string& sep =
",",
const std::string& quote =
"\"") :
115 bool inside_quotes =
false;
116 bool in_escape =
false;
117 while ( first != last ) {
124 else if ( s.find(c) != std::string::npos && !inside_quotes ) {
128 else if ( q.find(c) != std::string::npos ) {
129 inside_quotes = !inside_quotes;
131 else if ( e.find(c) != std::string::npos ) {
141template <
typename TokenizerFunc =
char_delimiter>
145 template <
typename Func>
149 std::string::const_iterator first;
150 std::string::const_iterator last;
154 explicit token_iter(Func& f_, std::string::const_iterator& first_, std::string::const_iterator& last_) :
159 f(first, last, token);
161 token_iter& operator++()
163 f(first, last, token);
166 token_iter operator++(
int)
168 token_iter retval = *
this;
172 bool operator==(token_iter other)
const
174 return (first == other.first) && (last == other.last) && (token == other.token);
176 bool operator!=(token_iter other)
const {
return !(*
this == other); }
177 const std::string& operator*()
const {
return token; }
178 const std::string& operator->()
const {
return token; }
180 using difference_type = std::ptrdiff_t;
181 using value_type = std::string;
182 using pointer =
const std::string*;
183 using reference =
const std::string&;
184 using iterator_category = std::input_iterator_tag;
187 using iter = token_iter<TokenizerFunc>;
190 using iterator = iter;
191 using const_iterator = iter;
192 using value_type = std::string;
194 iter begin() {
return iter(f, first, last); }
195 iter end() {
return iter(f, last, last); }
197 Tokenizer(
const std::string& s,
const TokenizerFunc& f = TokenizerFunc()) :
204 std::string::const_iterator first, last;
224std::string vformat_string(
size_t max_length,
const char* format, va_list args) __attribute__((format(printf, 2, 0)));
240std::string vformat_string(
const char* format, va_list args) __attribute__((format(printf, 1, 0)));
257std::string format_string(
size_t max_length,
const char* format, ...) __attribute__((format(printf, 2, 3)));
273std::
string format_string(const
char* format, ...) __attribute__((format(printf, 1, 2)));
void operator()(iter &first, iter last, std::string &token)
Definition stringize.h:83
void operator()(iter &first, iter last, std::string &token)
Sets pair<iter, iter> = <tok_end, next_tok>
Definition stringize.h:111