parse.ipp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com)
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Official repository: https://github.com/boostorg/json
  9. //
  10. #ifndef BOOST_JSON_IMPL_PARSE_IPP
  11. #define BOOST_JSON_IMPL_PARSE_IPP
  12. #include <boost/json/parse.hpp>
  13. #include <boost/json/parser.hpp>
  14. #include <boost/json/detail/except.hpp>
  15. BOOST_JSON_NS_BEGIN
  16. value
  17. parse(
  18. string_view s,
  19. error_code& ec,
  20. storage_ptr sp,
  21. const parse_options& opt)
  22. {
  23. unsigned char temp[
  24. BOOST_JSON_STACK_BUFFER_SIZE];
  25. parser p(storage_ptr(), opt, temp);
  26. p.reset(std::move(sp));
  27. p.write(s, ec);
  28. if(ec)
  29. return nullptr;
  30. return p.release();
  31. }
  32. value
  33. parse(
  34. string_view s,
  35. storage_ptr sp,
  36. const parse_options& opt)
  37. {
  38. error_code ec;
  39. auto jv = parse(
  40. s, ec, std::move(sp), opt);
  41. if(ec)
  42. detail::throw_system_error(ec,
  43. BOOST_JSON_SOURCE_POS);
  44. return jv;
  45. }
  46. BOOST_JSON_NS_END
  47. #endif