12 #ifndef SST_CORE_STRINGIZE_H
13 #define SST_CORE_STRINGIZE_H
26 sprintf(buffer,
"%f", val);
28 std::string buffer_str(buffer);
36 sprintf(buffer,
"%f", val);
38 std::string buffer_str(buffer);
43 to_string(int32_t val)
46 sprintf(buffer,
"%" PRId32, val);
48 std::string buffer_str(buffer);
53 to_string(int64_t val)
56 sprintf(buffer,
"%" PRId64, val);
58 std::string buffer_str(buffer);
63 to_string(uint32_t val)
66 sprintf(buffer,
"%" PRIu32, val);
68 std::string buffer_str(buffer);
73 to_string(uint64_t val)
76 sprintf(buffer,
"%" PRIu64, val);
78 std::string buffer_str(buffer);
83 strcasecmp(
const std::string& s1,
const std::string& s2)
85 return !::strcasecmp(s1.c_str(), s2.c_str());
89 to_lower(std::string& s)
91 for (
size_t i = 0; i < s.size(); i++ ) {
92 s[i] = std::tolower(s[i]);
99 auto start = s.find_first_not_of(
" \t\n\r\v\f");
100 if ( start != 0 ) { s.replace(s.begin(), s.begin() + (start),
""); }
101 auto end = s.find_last_not_of(
" \t\n\r\v\f");
102 if ( end != s.size() - 1 ) { s.replace(s.begin() + end + 1, s.end(),
""); }
107 typedef std::string::const_iterator iter;
108 const std::string delim;
109 char_delimiter(
const std::string& delim =
" \t\v\f\n\r") : delim(delim) {}
119 while ( first != last && delim.find(*first) != std::string::npos )
122 while ( first != last && delim.find(*first) == std::string::npos )
129 typedef std::string::const_iterator iter;
135 const std::string& esc =
"\\",
const std::string& sep =
",",
const std::string& quote =
"\"") :
148 bool inside_quotes =
false;
149 bool in_escape =
false;
150 while ( first != last ) {
157 else if ( s.find(c) != std::string::npos && !inside_quotes ) {
161 else if ( q.find(c) != std::string::npos ) {
162 inside_quotes = !inside_quotes;
164 else if ( e.find(c) != std::string::npos ) {
174 template <
typename TokenizerFunc =
char_delimiter>
178 template <
typename Func>
179 struct token_iter :
public std::iterator<std::input_iterator_tag, std::string>
182 std::string::const_iterator first;
183 std::string::const_iterator last;
187 explicit token_iter(Func& f_, std::string::const_iterator& first_, std::string::const_iterator& last_) :
192 f(first, last, token);
194 token_iter& operator++()
196 f(first, last, token);
199 token_iter operator++(
int)
201 token_iter retval = *
this;
205 bool operator==(token_iter other)
const
207 return (first == other.first) && (last == other.last) && (token == other.token);
209 bool operator!=(token_iter other)
const {
return !(*
this == other); }
210 const std::string& operator*()
const {
return token; }
211 const std::string& operator->()
const {
return token; }
214 typedef token_iter<TokenizerFunc> iter;
217 typedef iter iterator;
218 typedef iter const_iterator;
219 typedef std::string value_type;
221 iter begin() {
return iter(f, first, last); }
222 iter end() {
return iter(f, last, last); }
224 Tokenizer(
const std::string& s,
const TokenizerFunc& f = TokenizerFunc()) : first(s.begin()), last(s.end()), f(f) {}
227 std::string::const_iterator first, last;
233 #endif // SST_CORE_STRINGIZE_H
Definition: stringize.h:127
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:144
Definition: stringize.h:175
Definition: stringize.h:105
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:114