12#ifndef SST_CORE_STRINGIZE_H
13#define SST_CORE_STRINGIZE_H
25__attribute__((deprecated(
26 "SST::to_string() is deprecated and will be removed in SST 13. Please use std::to_string() instead"))) inline std::
30 return std::to_string(val);
33__attribute__((deprecated(
34 "SST::to_string() is deprecated and will be removed in SST 13. Please use std::to_string() instead"))) inline std::
38 return std::to_string(val);
41__attribute__((deprecated(
42 "SST::to_string() is deprecated and will be removed in SST 13. Please use std::to_string() instead"))) inline std::
44 to_string(int32_t val)
46 return std::to_string(val);
49__attribute__((deprecated(
50 "SST::to_string() is deprecated and will be removed in SST 13. Please use std::to_string() instead"))) inline std::
52 to_string(int64_t val)
54 return std::to_string(val);
57__attribute__((deprecated(
58 "SST::to_string() is deprecated and will be removed in SST 13. Please use std::to_string() instead"))) inline std::
60 to_string(uint32_t val)
62 return std::to_string(val);
65__attribute__((deprecated(
66 "SST::to_string() is deprecated and will be removed in SST 13. Please use std::to_string() instead"))) inline std::
68 to_string(uint64_t val)
70 return std::to_string(val);
74strcasecmp(
const std::string& s1,
const std::string& s2)
76 return !::strcasecmp(s1.c_str(), s2.c_str());
80to_lower(std::string& s)
82 for (
size_t i = 0; i < s.size(); i++ ) {
83 s[i] = std::tolower(s[i]);
90 auto start = s.find_first_not_of(
" \t\n\r\v\f");
91 if ( start != 0 ) { s.replace(s.begin(), s.begin() + (start),
""); }
92 auto end = s.find_last_not_of(
" \t\n\r\v\f");
93 if ( end != s.size() - 1 ) { s.replace(s.begin() + end + 1, s.end(),
""); }
97tokenize(std::vector<std::string>& output,
const std::string& input,
const std::string& delim,
bool trim_ws =
false)
100 size_t end = input.find(delim);
103 while ( end != std::string::npos ) {
104 token = input.substr(start, end - start);
105 if ( trim_ws ) trim(token);
106 output.push_back(token);
107 start = end + delim.length();
108 end = input.find(delim, start);
111 token = input.substr(start, end);
112 if ( trim_ws ) trim(token);
113 output.push_back(token);
118 typedef std::string::const_iterator iter;
119 const std::string delim;
120 char_delimiter(
const std::string& delim =
" \t\v\f\n\r") : delim(delim) {}
130 while ( first != last && delim.find(*first) != std::string::npos )
133 while ( first != last && delim.find(*first) == std::string::npos )
140 typedef std::string::const_iterator iter;
146 const std::string& esc =
"\\",
const std::string& sep =
",",
const std::string& quote =
"\"") :
159 bool inside_quotes =
false;
160 bool in_escape =
false;
161 while ( first != last ) {
168 else if ( s.find(c) != std::string::npos && !inside_quotes ) {
172 else if ( q.find(c) != std::string::npos ) {
173 inside_quotes = !inside_quotes;
175 else if ( e.find(c) != std::string::npos ) {
185template <
typename TokenizerFunc =
char_delimiter>
189 template <
typename Func>
190 struct token_iter :
public std::iterator<std::input_iterator_tag, std::string>
193 std::string::const_iterator first;
194 std::string::const_iterator last;
198 explicit token_iter(Func& f_, std::string::const_iterator& first_, std::string::const_iterator& last_) :
203 f(first, last, token);
205 token_iter& operator++()
207 f(first, last, token);
210 token_iter operator++(
int)
212 token_iter retval = *
this;
216 bool operator==(token_iter other)
const
218 return (first == other.first) && (last == other.last) && (token == other.token);
220 bool operator!=(token_iter other)
const {
return !(*
this == other); }
221 const std::string& operator*()
const {
return token; }
222 const std::string& operator->()
const {
return token; }
225 typedef token_iter<TokenizerFunc> iter;
228 typedef iter iterator;
229 typedef iter const_iterator;
230 typedef std::string value_type;
232 iter begin() {
return iter(f, first, last); }
233 iter end() {
return iter(f, last, last); }
235 Tokenizer(
const std::string& s,
const TokenizerFunc& f = TokenizerFunc()) : first(s.begin()), last(s.end()), f(f) {}
238 std::string::const_iterator first, last;
258std::string vformat_string(
size_t max_length,
const char* format, va_list args);
274std::string vformat_string(
const char* format, va_list args);
291std::string format_string(
size_t max_length,
const char* format, ...) __attribute__((format(printf, 2, 3)));
307std::
string format_string(const
char* format, ...) __attribute__((format(printf, 1, 2)));
Definition: stringize.h:187
Definition: stringize.h:117
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:125
Definition: stringize.h:139
void operator()(iter &first, iter last, std::string &token)
Definition: stringize.h:155