12 #ifndef _H_SST_CORE_STRINGIZE
13 #define _H_SST_CORE_STRINGIZE
22 inline std::string to_string(
double val) {
24 sprintf(buffer,
"%f", val);
26 std::string buffer_str(buffer);
30 inline std::string to_string(
float val) {
32 sprintf(buffer,
"%f", val);
34 std::string buffer_str(buffer);
38 inline std::string to_string(int32_t val) {
40 sprintf(buffer,
"%" PRId32, val);
42 std::string buffer_str(buffer);
46 inline std::string to_string(int64_t val) {
48 sprintf(buffer,
"%" PRId64, val);
50 std::string buffer_str(buffer);
54 inline std::string to_string(uint32_t val) {
56 sprintf(buffer,
"%" PRIu32, val);
58 std::string buffer_str(buffer);
62 inline std::string to_string(uint64_t val) {
64 sprintf(buffer,
"%" PRIu64, val);
66 std::string buffer_str(buffer);
71 inline bool strcasecmp(
const std::string &s1,
const std::string &s2) {
72 return !::strcasecmp(s1.c_str(), s2.c_str());
75 inline void to_lower(std::string &s) {
76 for (
size_t i = 0 ; i < s.size() ; i++ ) {
77 s[i] = std::tolower(s[i]);
82 inline void trim(std::string &s) {
83 auto start = s.find_first_not_of(
" \t\n\r\v\f");
85 s.replace(s.begin(), s.begin() + (start),
"");
87 auto end = s.find_last_not_of(
" \t\n\r\v\f");
88 if ( end != s.size() -1 ) {
89 s.replace(s.begin() + end + 1, s.end(),
"");
96 typedef std::string::const_iterator iter;
97 const std::string delim;
104 void operator()(iter &first, iter last, std::string &token) {
108 while ( first != last && delim.find(*first) != std::string::npos )
111 while ( first != last && delim.find(*first) == std::string::npos )
120 typedef std::string::const_iterator iter;
125 escaped_list_separator(
const std::string &esc=
"\\",
const std::string &sep=
",",
const std::string "e=
"\"")
126 : e(esc), s(sep), q(quote) { }
132 bool operator()(iter &first, iter last, std::string &token) {
135 bool inside_quotes =
false;
136 bool in_escape =
false;
137 while ( first != last ) {
143 }
else if ( s.find(c) != std::string::npos && !inside_quotes ) {
146 }
else if ( q.find(c) != std::string::npos ) {
147 inside_quotes = !inside_quotes;
148 }
else if ( e.find(c) != std::string::npos ) {
160 template<
typename TokenizerFunc =
char_delimiter >
163 template <
typename Func>
165 :
public std::iterator< std::input_iterator_tag, std::string >
168 std::string::const_iterator first;
169 std::string::const_iterator last;
172 explicit token_iter(Func& f_, std::string::const_iterator& first_, std::string::const_iterator& last_)
173 : f(f_), first(first_), last(last_)
175 f(first, last, token);
177 token_iter& operator++() { f(first, last, token);
return *
this; }
178 token_iter operator++(
int) {token_iter retval = *
this; ++(*this);
return retval;}
179 bool operator==(token_iter other)
const {
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; }
187 typedef token_iter<TokenizerFunc> iter;
189 typedef iter iterator;
190 typedef iter const_iterator;
191 typedef std::string value_type;
193 iter begin() {
return iter(f, first, last); }
194 iter end() {
return iter(f, last, last); }
196 Tokenizer(
const std::string &s,
const TokenizerFunc& f = TokenizerFunc())
197 : first(s.begin()), last(s.end()), f(f) { }
200 std::string::const_iterator first, last;
Definition: stringize.h:119
Definition: stringize.h:161
bool operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:132
Definition: stringize.h:95
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:104