parse.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_PARSE_HPP
  11. #define BOOST_JSON_PARSE_HPP
  12. #include <boost/json/detail/config.hpp>
  13. #include <boost/json/error.hpp>
  14. #include <boost/json/parse_options.hpp>
  15. #include <boost/json/storage_ptr.hpp>
  16. #include <boost/json/string_view.hpp>
  17. #include <boost/json/value.hpp>
  18. BOOST_JSON_NS_BEGIN
  19. /** Return parsed JSON as a @ref value.
  20. This function parses an entire string in one
  21. step to produce a complete JSON object, returned
  22. as a @ref value. If the buffer does not contain a
  23. complete serialized JSON, an error occurs. In this
  24. case the returned value will be null, using the
  25. default memory resource.
  26. @par Complexity
  27. Linear in `s.size()`.
  28. @par Exception Safety
  29. Strong guarantee.
  30. Calls to `memory_resource::allocate` may throw.
  31. @return A value representing the parsed JSON,
  32. or a null if any error occurred.
  33. @param s The string to parse.
  34. @param ec Set to the error, if any occurred.
  35. @param sp The memory resource that the new value and all
  36. of its elements will use. If this parameter is omitted,
  37. the default memory resource is used.
  38. @param opt The options for the parser. If this parameter
  39. is omitted, the parser will accept only standard JSON.
  40. @see
  41. @ref parse_options,
  42. @ref stream_parser.
  43. */
  44. BOOST_JSON_DECL
  45. value
  46. parse(
  47. string_view s,
  48. error_code& ec,
  49. storage_ptr sp = {},
  50. parse_options const& opt = {});
  51. /** Parse a string of JSON into a @ref value.
  52. This function parses an entire string in one
  53. step to produce a complete JSON object, returned
  54. as a @ref value. If the buffer does not contain a
  55. complete serialized JSON, an exception is thrown.
  56. @par Complexity
  57. Linear in `s.size()`.
  58. @par Exception Safety
  59. Strong guarantee.
  60. Calls to `memory_resource::allocate` may throw.
  61. @return A value representing the parsed
  62. JSON upon success.
  63. @param s The string to parse.
  64. @param sp The memory resource that the new value and all
  65. of its elements will use. If this parameter is omitted,
  66. the default memory resource is used.
  67. @param opt The options for the parser. If this parameter
  68. is omitted, the parser will accept only standard JSON.
  69. @throw system_error Thrown on failure.
  70. @see
  71. @ref parse_options,
  72. @ref stream_parser.
  73. */
  74. BOOST_JSON_DECL
  75. value
  76. parse(
  77. string_view s,
  78. storage_ptr sp = {},
  79. parse_options const& opt = {});
  80. BOOST_JSON_NS_END
  81. #endif