Electroneum
Loading...
Searching...
No Matches
epee::misc_utils::parse Namespace Reference

Functions

bool isspace (char c)
bool isdigit (char c)
std::string transform_to_escape_sequence (const std::string &src)
void match_string2 (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, std::string &val)
bool match_string (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, std::string &val)
void match_number2 (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, boost::string_ref &val, bool &is_float_val, bool &is_signed_val)
bool match_number (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, boost::string_ref &val)
void match_word2 (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, boost::string_ref &val)
bool match_word (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, boost::string_ref &val)
bool match_word_with_extrasymb (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, std::string &val)
bool match_word_til_equal_mark (std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, std::string::const_iterator &word_end)

Function Documentation

◆ isdigit()

bool epee::misc_utils::parse::isdigit ( char c)
inline

Definition at line 70 of file parserse_base_utils.h.

71 {
72 return lut[(uint8_t)c] & 1;
73 }
unsigned char uint8_t
Definition stdint.h:124
Here is the caller graph for this function:

◆ isspace()

bool epee::misc_utils::parse::isspace ( char c)
inline

Definition at line 65 of file parserse_base_utils.h.

66 {
67 return lut[(uint8_t)c] & 8;
68 }
Here is the caller graph for this function:

◆ match_number()

bool epee::misc_utils::parse::match_number ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
boost::string_ref & val )
inline

Definition at line 234 of file parserse_base_utils.h.

235 {
236 try
237 {
238 bool is_v_float = false;bool is_signed_val = false;
239 match_number2(star_end_string, buf_end, val, is_v_float, is_signed_val);
240 return !is_v_float;
241 }
242 catch(...)
243 {
244 return false;
245 }
246 }
void match_number2(std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, boost::string_ref &val, bool &is_float_val, bool &is_signed_val)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ match_number2()

void epee::misc_utils::parse::match_number2 ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
boost::string_ref & val,
bool & is_float_val,
bool & is_signed_val )
inline

Definition at line 198 of file parserse_base_utils.h.

199 {
200 val.clear();
201 uint8_t float_flag = 0;
202 is_signed_val = false;
203 size_t chars = 0;
204 std::string::const_iterator it = star_end_string;
205 if (it != buf_end && *it == '-')
206 {
207 is_signed_val = true;
208 ++chars;
209 ++it;
210 }
211 for(;it != buf_end;it++)
212 {
213 const uint8_t flags = lut[(uint8_t)*it];
214 if (flags & 16)
215 {
216 float_flag |= flags;
217 ++chars;
218 }
219 else
220 {
221 val = boost::string_ref(&*star_end_string, chars);
222 if(val.size())
223 {
224 star_end_string = --it;
225 is_float_val = !!(float_flag & 2);
226 return;
227 }
228 else
229 ASSERT_MES_AND_THROW("wrong number in json entry: " << std::string(star_end_string, buf_end));
230 }
231 }
232 ASSERT_MES_AND_THROW("wrong number in json entry: " << std::string(star_end_string, buf_end));
233 }
#define ASSERT_MES_AND_THROW(message)
Here is the caller graph for this function:

◆ match_string()

bool epee::misc_utils::parse::match_string ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
std::string & val )
inline

Definition at line 185 of file parserse_base_utils.h.

186 {
187 try
188 {
189
190 match_string2(star_end_string, buf_end, val);
191 return true;
192 }
193 catch(...)
194 {
195 return false;
196 }
197 }
void match_string2(std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, std::string &val)
Here is the call graph for this function:

◆ match_string2()

void epee::misc_utils::parse::match_string2 ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
std::string & val )
inline

Definition at line 128 of file parserse_base_utils.h.

129 {
130 bool escape_mode = false;
131 std::string::const_iterator it = star_end_string;
132 ++it;
133 std::string::const_iterator fi = it;
134 while (fi != buf_end && ((lut[(uint8_t)*fi] & 32)) == 0)
135 ++fi;
136 val.assign(it, fi);
137 val.reserve(std::distance(star_end_string, buf_end));
138 it = fi;
139 for(;it != buf_end;it++)
140 {
141 if(escape_mode/*prev_ch == '\\'*/)
142 {
143 switch(*it)
144 {
145 case 'b': //Backspace (ascii code 08)
146 val.push_back(0x08);break;
147 case 'f': //Form feed (ascii code 0C)
148 val.push_back(0x0C);break;
149 case 'n': //New line
150 val.push_back('\n');break;
151 case 'r': //Carriage return
152 val.push_back('\r');break;
153 case 't': //Tab
154 val.push_back('\t');break;
155 case 'v': //Vertical tab
156 val.push_back('\v');break;
157 case '\'': //Apostrophe or single quote
158 val.push_back('\'');break;
159 case '"': //Double quote
160 val.push_back('"');break;
161 case '\\': //Backslash character
162 val.push_back('\\');break;
163 case '/': //Slash character
164 val.push_back('/');break;
165 default:
166 val.push_back(*it);
167 LOG_PRINT_L0("Unknown escape sequence :\"\\" << *it << "\"");
168 }
169 escape_mode = false;
170 }else if(*it == '"')
171 {
172 star_end_string = it;
173 return;
174 }else if(*it == '\\')
175 {
176 escape_mode = true;
177 }
178 else
179 {
180 val.push_back(*it);
181 }
182 }
183 ASSERT_MES_AND_THROW("Failed to match string in json entry: " << std::string(star_end_string, buf_end));
184 }
#define LOG_PRINT_L0(x)
Definition misc_log_ex.h:99
Here is the caller graph for this function:

◆ match_word()

bool epee::misc_utils::parse::match_word ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
boost::string_ref & val )
inline

Definition at line 266 of file parserse_base_utils.h.

267 {
268 try
269 {
270 match_word2(star_end_string, buf_end, val);
271 return true;
272 }
273 catch(...)
274 {
275 return false;
276 }
277 }
void match_word2(std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, boost::string_ref &val)
Here is the call graph for this function:

◆ match_word2()

void epee::misc_utils::parse::match_word2 ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
boost::string_ref & val )
inline

Definition at line 247 of file parserse_base_utils.h.

248 {
249 val.clear();
250
251 for(std::string::const_iterator it = star_end_string;it != buf_end;it++)
252 {
253 if (!(lut[(uint8_t)*it] & 4))
254 {
255 val = boost::string_ref(&*star_end_string, std::distance(star_end_string, it));
256 if(val.size())
257 {
258 star_end_string = --it;
259 return;
260 }else
261 ASSERT_MES_AND_THROW("failed to match word number in json entry: " << std::string(star_end_string, buf_end));
262 }
263 }
264 ASSERT_MES_AND_THROW("failed to match word number in json entry: " << std::string(star_end_string, buf_end));
265 }
Here is the caller graph for this function:

◆ match_word_til_equal_mark()

bool epee::misc_utils::parse::match_word_til_equal_mark ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
std::string::const_iterator & word_end )
inline

Definition at line 297 of file parserse_base_utils.h.

298 {
299 word_end = star_end_string;
300
301 for(std::string::const_iterator it = star_end_string;it != buf_end;it++)
302 {
303 if(isspace(*it))
304 {
305
306 continue;
307 }else if( *it == '=' )
308 {
309 star_end_string = it;
310 word_end = it;
311 return true;
312 }
313 }
314 return false;
315 }
Here is the call graph for this function:

◆ match_word_with_extrasymb()

bool epee::misc_utils::parse::match_word_with_extrasymb ( std::string::const_iterator & star_end_string,
std::string::const_iterator buf_end,
std::string & val )
inline

Definition at line 278 of file parserse_base_utils.h.

279 {
280 val.clear();
281
282 for(std::string::const_iterator it = star_end_string;it != buf_end;it++)
283 {
284 if(!isalnum(*it) && *it != '-' && *it != '_')
285 {
286 val.assign(star_end_string, it);
287 if(val.size())
288 {
289 star_end_string = --it;
290 return true;
291 }else
292 return false;
293 }
294 }
295 return false;
296 }

◆ transform_to_escape_sequence()

std::string epee::misc_utils::parse::transform_to_escape_sequence ( const std::string & src)
inline

Definition at line 75 of file parserse_base_utils.h.

76 {
77 static const char escaped[] = "\b\f\n\r\t\v\"\\/";
78 std::string::const_iterator it = std::find_first_of(src.begin(), src.end(), escaped, escaped + sizeof(escaped));
79 if (it == src.end())
80 return src;
81
82 std::string res;
83 res.reserve(2 * src.size());
84 res.assign(src.begin(), it);
85 for(; it!=src.end(); ++it)
86 {
87 switch(*it)
88 {
89 case '\b': //Backspace (ascii code 08)
90 res+="\\b"; break;
91 case '\f': //Form feed (ascii code 0C)
92 res+="\\f"; break;
93 case '\n': //New line
94 res+="\\n"; break;
95 case '\r': //Carriage return
96 res+="\\r"; break;
97 case '\t': //Tab
98 res+="\\t"; break;
99 case '\v': //Vertical tab
100 res+="\\v"; break;
101 //case '\'': //Apostrophe or single quote
102 // res+="\\'"; break;
103 case '"': //Double quote
104 res+="\\\""; break;
105 case '\\': //Backslash caracter
106 res+="\\\\"; break;
107 case '/': //Backslash caracter
108 res+="\\/"; break;
109 default:
110 res.push_back(*it);
111 }
112 }
113 return res;
114 }
const char * res
Here is the caller graph for this function: