50 {
52
53 std::string::const_iterator sub_element_start;
54 std::string name;
55 typename t_storage::harray h_array = nullptr;
56 enum match_state
57 {
58 match_state_lookup_for_section_start,
59 match_state_lookup_for_name,
60 match_state_waiting_separator,
61 match_state_wonder_after_separator,
62 match_state_wonder_after_value,
63 match_state_wonder_array,
64 match_state_array_after_value,
65 match_state_array_waiting_value,
66 match_state_error
67 };
68
69 enum array_mode
70 {
71 array_mode_undifined = 0,
72 array_mode_sections,
73 array_mode_string,
74 array_mode_numbers,
75 array_mode_booleans
76 };
77
78 match_state
state = match_state_lookup_for_section_start;
79 array_mode array_md = array_mode_undifined;
80 std::string::const_iterator it = sec_buf_begin;
81 for(;it != buf_end;it++)
82 {
84 {
85 case match_state_lookup_for_section_start:
86 if(*it == '{')
87 state = match_state_lookup_for_name;
89 break;
90 case match_state_lookup_for_name:
91 switch(*it)
92 {
93 case '"':
95 state = match_state_waiting_separator;
96 break;
97 case '}':
98
99
100 sec_buf_begin = it;
101 return;
102 default:
104 }
105 break;
106 case match_state_waiting_separator:
107 if(*it == ':')
108 state = match_state_wonder_after_separator;
110 break;
111 case match_state_wonder_after_separator:
112 if(*it == '"')
113 {
114 std::string val;
116
117 stg.set_value(name, std::move(val), current_section);
118 state = match_state_wonder_after_value;
120 {
121 boost::string_ref val;
122 bool is_v_float = false;bool is_signed = false;
124 if(!is_v_float)
125 {
126 if(is_signed)
127 {
128 errno = 0;
129 int64_t nval = strtoll(val.data(), NULL, 10);
130 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
131 stg.set_value(name, nval, current_section);
132 }else
133 {
134 errno = 0;
135 uint64_t nval = strtoull(val.data(), NULL, 10);
136 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
137 stg.set_value(name, nval, current_section);
138 }
139 }else
140 {
141 errno = 0;
142 double nval = strtod(val.data(), NULL);
143 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
144 stg.set_value(name, nval, current_section);
145 }
146 state = match_state_wonder_after_value;
147 }else if(isalpha(*it) )
148 {
149 boost::string_ref word;
151 if(boost::iequals(word, "null"))
152 {
153 state = match_state_wonder_after_value;
154
155 }else if(boost::iequals(word, "true"))
156 {
157 stg.set_value(name, true, current_section);
158 state = match_state_wonder_after_value;
159 }else if(boost::iequals(word, "false"))
160 {
161 stg.set_value(name, false, current_section);
162 state = match_state_wonder_after_value;
164 }else if(*it == '{')
165 {
166
167 typename t_storage::hsection new_sec = stg.open_section(name, current_section, true);
169 run_handler(new_sec, it, buf_end, stg, recursion + 1);
170 state = match_state_wonder_after_value;
171 }else if(*it == '[')
172 {
173 state = match_state_wonder_array;
175 break;
176 case match_state_wonder_after_value:
177 if(*it == ',')
178 state = match_state_lookup_for_name;
179 else if(*it == '}')
180 {
181
182 sec_buf_begin = it;
183 return;
185 break;
186 case match_state_wonder_array:
187 if(*it == '[')
188 {
190
191 }
192 if(*it == '{')
193 {
194
195 typename t_storage::hsection new_sec = nullptr;
196 h_array = stg.insert_first_section(name, new_sec, current_section);
198 run_handler(new_sec, it, buf_end, stg, recursion + 1);
199 state = match_state_array_after_value;
200 array_md = array_mode_sections;
201 }else if(*it == '"')
202 {
203
204 std::string val;
206 h_array = stg.insert_first_value(name, std::move(val), current_section);
208 state = match_state_array_after_value;
209 array_md = array_mode_string;
211 {
212 boost::string_ref val;
213 bool is_v_float = false;bool is_signed_val = false;
215 if(!is_v_float)
216 {
217 if (is_signed_val)
218 {
219 errno = 0;
220 int64_t nval = strtoll(val.data(), NULL, 10);
221 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
222 h_array = stg.insert_first_value(name, nval, current_section);
223 }else
224 {
225 errno = 0;
226 uint64_t nval = strtoull(val.data(), NULL, 10);
227 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
228 h_array = stg.insert_first_value(name, nval, current_section);
229 }
231 }else
232 {
233 errno = 0;
234 double nval = strtod(val.data(), NULL);
235 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
236 h_array = stg.insert_first_value(name, nval, current_section);
238 }
239
240 state = match_state_array_after_value;
241 array_md = array_mode_numbers;
242 }else if(*it == ']')
243 {
244 array_md = array_mode_undifined;
245 state = match_state_wonder_after_value;
246 }else if(isalpha(*it) )
247 {
248 boost::string_ref word;
250 if(boost::iequals(word, "true"))
251 {
252 h_array = stg.insert_first_value(name, true, current_section);
254 state = match_state_array_after_value;
255 array_md = array_mode_booleans;
256 }else if(boost::iequals(word, "false"))
257 {
258 h_array = stg.insert_first_value(name, false, current_section);
260 state = match_state_array_after_value;
261 array_md = array_mode_booleans;
262
265 break;
266 case match_state_array_after_value:
267 if(*it == ',')
268 state = match_state_array_waiting_value;
269 else if(*it == ']')
270 {
271 h_array = nullptr;
272 array_md = array_mode_undifined;
273 state = match_state_wonder_after_value;
275 break;
276 case match_state_array_waiting_value:
277 switch(array_md)
278 {
279 case array_mode_sections:
280 if(*it == '{')
281 {
282 typename t_storage::hsection new_sec = NULL;
283 bool res = stg.insert_next_section(h_array, new_sec);
285 run_handler(new_sec, it, buf_end, stg, recursion + 1);
286 state = match_state_array_after_value;
288 break;
289 case array_mode_string:
290 if(*it == '"')
291 {
292 std::string val;
294 bool res = stg.insert_next_value(h_array, std::move(val));
296 state = match_state_array_after_value;
298 break;
299 case array_mode_numbers:
301 {
302 boost::string_ref val;
303 bool is_v_float = false;bool is_signed_val = false;
305 bool insert_res = false;
306 if(!is_v_float)
307 {
308 if (is_signed_val)
309 {
310 errno = 0;
311 int64_t nval = strtoll(val.data(), NULL, 10);
312 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
313 insert_res = stg.insert_next_value(h_array, nval);
314 }else
315 {
316 errno = 0;
317 uint64_t nval = strtoull(val.data(), NULL, 10);
318 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
319 insert_res = stg.insert_next_value(h_array, nval);
320 }
321 }else
322 {
323 errno = 0;
324 double nval = strtod(val.data(), NULL);
325 if (errno) throw std::runtime_error("Invalid number: " + std::string(val));
326 insert_res = stg.insert_next_value(h_array, nval);
327 }
329 state = match_state_array_after_value;
330 array_md = array_mode_numbers;
332 break;
333 case array_mode_booleans:
334 if(isalpha(*it) )
335 {
336 boost::string_ref word;
338 if(boost::iequals(word, "true"))
339 {
340 bool r = stg.insert_next_value(h_array, true);
342 state = match_state_array_after_value;
343 }else if(boost::iequals(word, "false"))
344 {
345 bool r = stg.insert_next_value(h_array, false);
347 state = match_state_array_after_value;
348 }
351 break;
352 case array_mode_undifined:
353 default:
355 }
356 break;
357 case match_state_error:
358 default:
360 }
361 }
362 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
#define ASSERT_MES_AND_THROW(message)
void match_string2(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)
void match_word2(std::string::const_iterator &star_end_string, std::string::const_iterator buf_end, boost::string_ref &val)
#define EPEE_JSON_RECURSION_LIMIT_INTERNAL
unsigned __int64 uint64_t