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");
43 if ( start != 0 ) { s.replace(s.begin(), s.begin() + (start),
""); }
44 auto end = s.find_last_not_of(
" \t\n\r\v\f");
45 if ( end != s.size() - 1 ) { s.replace(s.begin() + end + 1, s.end(),
""); }
49 tokenize(std::vector<std::string>& output,
const std::string& input,
const std::string& delim,
bool trim_ws =
false)
52 size_t end = input.find(delim);
55 while ( end != std::string::npos ) {
56 token = input.substr(start, end - start);
57 if ( trim_ws ) trim(token);
58 output.push_back(token);
59 start = end + delim.length();
60 end = input.find(delim, start);
63 token = input.substr(start, end);
64 if ( trim_ws ) trim(token);
65 output.push_back(token);
70 typedef std::string::const_iterator iter;
71 const std::string delim;
72 char_delimiter(
const std::string& delim =
" \t\v\f\n\r") : delim(delim) {}
77 void operator()(iter& first, iter last, std::string& token)
82 while ( first != last && delim.find(*first) != std::string::npos )
85 while ( first != last && delim.find(*first) == std::string::npos )
92 typedef std::string::const_iterator iter;
98 const std::string& esc =
"\\",
const std::string& sep =
",",
const std::string& quote =
"\"") :
111 bool inside_quotes =
false;
112 bool in_escape =
false;
113 while ( first != last ) {
120 else if ( s.find(c) != std::string::npos && !inside_quotes ) {
124 else if ( q.find(c) != std::string::npos ) {
125 inside_quotes = !inside_quotes;
127 else if ( e.find(c) != std::string::npos ) {
137 template <
typename TokenizerFunc =
char_delimiter>
141 template <
typename Func>
145 std::string::const_iterator first;
146 std::string::const_iterator last;
150 explicit token_iter(Func& f_, std::string::const_iterator& first_, std::string::const_iterator& last_) :
155 f(first, last, token);
157 token_iter& operator++()
159 f(first, last, token);
162 token_iter operator++(
int)
164 token_iter retval = *
this;
168 bool operator==(token_iter other)
const
170 return (first == other.first) && (last == other.last) && (token == other.token);
172 bool operator!=(token_iter other)
const {
return !(*
this == other); }
173 const std::string& operator*()
const {
return token; }
174 const std::string& operator->()
const {
return token; }
176 using difference_type = std::ptrdiff_t;
177 using value_type = std::string;
178 using pointer =
const std::string*;
179 using reference =
const std::string&;
180 using iterator_category = std::input_iterator_tag;
183 typedef token_iter<TokenizerFunc> iter;
186 typedef iter iterator;
187 typedef iter const_iterator;
188 typedef std::string value_type;
190 iter begin() {
return iter(f, first, last); }
191 iter end() {
return iter(f, last, last); }
193 Tokenizer(
const std::string& s,
const TokenizerFunc& f = TokenizerFunc()) : first(s.begin()), last(s.end()), f(f) {}
196 std::string::const_iterator first, last;
216 std::string vformat_string(
size_t max_length,
const char* format, va_list args);
232 std::string vformat_string(
const char* format, va_list args);
249 std::string format_string(
size_t max_length,
const char* format, ...) __attribute__((format(printf, 2, 3)));
265 std::
string format_string(const
char* format, ...) __attribute__((format(printf, 1, 2)));
Definition: stringize.h:139
Definition: stringize.h:69
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:77
Definition: stringize.h:91
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:107