| 235 | // return type is just bool. |
| 236 | template<typename Callbacks> |
| 237 | bool parse( |
| 238 | std::string_view str, |
| 239 | std::string_view filename, |
| 240 | Callbacks const & callbacks, |
| 241 | int max_recursion = 512) |
| 242 | { |
| 243 | auto const range = boost::parser::as_utf32(str); |
| 244 | using iter_t = decltype(range.begin()); |
| 245 | |
| 246 | if (max_recursion <= 0) |
| 247 | max_recursion = INT_MAX; |
| 248 | |
| 249 | global_state globals{0, max_recursion}; |
| 250 | // This is a different error handler from the json.cpp example, just |
| 251 | // to show different options. |
| 252 | bp::stream_error_handler error_handler(filename); |
| 253 | auto const parser = bp::with_error_handler( |
| 254 | bp::with_globals(value, globals), error_handler); |
| 255 | |
| 256 | try { |
| 257 | // This is identical to the parse() call in json.cpp, except that |
| 258 | // it is callback_parse() instead, and it takes the callbacks |
| 259 | // parameter. |
| 260 | return bp::callback_parse(range, parser, ws, callbacks); |
| 261 | } catch (excessive_nesting<iter_t> const & e) { |
| 262 | std::string const message = "error: Exceeded maximum number (" + |
| 263 | std::to_string(max_recursion) + |
| 264 | ") of open arrays and/or objects"; |
| 265 | bp::write_formatted_message( |
| 266 | std::cout, |
| 267 | filename, |
| 268 | range.begin(), |
| 269 | e.iter, |
| 270 | range.end(), |
| 271 | message); |
| 272 | } |
| 273 | |
| 274 | return {}; |
| 275 | } |
| 276 | |
| 277 | } |
| 278 |
no test coverage detected