12 #ifndef SST_CORE_STRINGIZE_H 13 #define SST_CORE_STRINGIZE_H 26 strcasecmp(
const std::string& s1,
const std::string& s2)
28 return !::strcasecmp(s1.c_str(), s2.c_str());
32 to_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(),
"");
53 tokenize(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 if ( input.empty() ) {
71 token = input.substr(start, end);
72 if ( trim_ws ) trim(token);
73 output.push_back(token);
78 using iter = std::string::const_iterator;
79 const std::string delim;
80 explicit char_delimiter(
const std::string& delim =
" \t\v\f\n\r") :
87 void operator()(iter& first, iter last, std::string& token)
92 while ( first != last && delim.find(*first) != std::string::npos )
95 while ( first != last && delim.find(*first) == std::string::npos )
102 using iter = std::string::const_iterator;
106 const std::string& esc =
"\\",
const std::string& sep =
",",
const std::string& quote =
"\"") :
119 bool inside_quotes =
false;
120 bool in_escape =
false;
121 while ( first != last ) {
128 else if ( s.find(c) != std::string::npos && !inside_quotes ) {
132 else if ( q.find(c) != std::string::npos ) {
133 inside_quotes = !inside_quotes;
135 else if ( e.find(c) != std::string::npos ) {
145 template <
typename TokenizerFunc =
char_delimiter>
149 template <
typename Func>
153 std::string::const_iterator first;
154 std::string::const_iterator last;
158 explicit token_iter(Func& f_, std::string::const_iterator& first_, std::string::const_iterator& last_) :
163 f(first, last, token);
165 token_iter& operator++()
167 f(first, last, token);
170 token_iter operator++(
int)
172 token_iter retval = *
this;
176 bool operator==(token_iter other)
const 178 return (first == other.first) && (last == other.last) && (token == other.token);
180 bool operator!=(token_iter other)
const {
return !(*
this == other); }
181 const std::string& operator*()
const {
return token; }
182 const std::string& operator->()
const {
return token; }
184 using difference_type = std::ptrdiff_t;
185 using value_type = std::string;
186 using pointer =
const std::string*;
187 using reference =
const std::string&;
188 using iterator_category = std::input_iterator_tag;
191 using iter = token_iter<TokenizerFunc>;
194 using iterator = iter;
195 using const_iterator = iter;
196 using value_type = std::string;
198 iter begin() {
return iter(f, first, last); }
199 iter end() {
return iter(f, last, last); }
201 Tokenizer(
const std::string& s,
const TokenizerFunc& f = TokenizerFunc()) :
208 std::string::const_iterator first, last;
228 std::string vformat_string(
size_t max_length,
const char* format, va_list args) __attribute__((format(printf, 2, 0)));
244 std::string vformat_string(
const char* format, va_list args) __attribute__((format(printf, 1, 0)));
261 std::string format_string(
size_t max_length,
const char* format, ...) __attribute__((format(printf, 2, 3)));
277 std::
string format_string(const
char* format, ...) __attribute__((format(printf, 1, 2)));
281 #endif // SST_CORE_STRINGIZE_H Definition: stringize.h:100
void operator()(iter &first, iter last, std::string &token)
Sets pair<iter, iter> = <tok_end, next_tok>
Definition: stringize.h:115
Definition: stringize.h:146
Definition: stringize.h:76
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:87