parse.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. namespace boost {
  19. namespace json {
  20. /** Return parsed JSON as a @ref value.
  21. This function parses input in one step to produce a complete JSON @ref
  22. value. If the input does not contain a complete serialized JSON, an error
  23. occurs. In this case **(1)**, **(2)**, **(4)**, and **(5)** return a null
  24. value that uses the
  25. \<\<default_memory_resource,default memory resource\>\>, and set `ec` to
  26. the corresponding error value. **(3)** and **(6)** throw an exception.
  27. @par Complexity
  28. @li **(1)**, **(2)**, **(3)** linear in `s.size()`.
  29. @li **(4)**, **(5)**, **(6)** linear in the size of consumed input.
  30. @par Exception Safety
  31. @li **(1)**, **(2)**, **(3)** strong guarantee.
  32. @li **(4)**, **(5)**, **(6)** basic guarantee.
  33. __(3)__, **(6)** throw `boost::system::system_error` on failed parse.
  34. Calls to `memory_resource::allocate` may throw.
  35. The stream `is` may throw as described by @ref std::ios::exceptions.
  36. @return A value representing the parsed JSON.
  37. @param s The string to parse.
  38. @param ec Set to the error, if any occurred.
  39. @param sp The memory resource that the new value and all of its elements
  40. will use.
  41. @param opt The options for the parser. If this parameter is omitted, the
  42. parser will accept only standard JSON.
  43. @see @ref parse_options, @ref stream_parser, @ref value::operator>>.
  44. @{
  45. */
  46. BOOST_JSON_DECL
  47. value
  48. parse(
  49. string_view s,
  50. system::error_code& ec,
  51. storage_ptr sp = {},
  52. parse_options const& opt = {});
  53. /// Overload
  54. BOOST_JSON_DECL
  55. value
  56. parse(
  57. string_view s,
  58. std::error_code& ec,
  59. storage_ptr sp = {},
  60. parse_options const& opt = {});
  61. /// Overload
  62. BOOST_JSON_DECL
  63. value
  64. parse(
  65. string_view s,
  66. storage_ptr sp = {},
  67. parse_options const& opt = {});
  68. /** Overload
  69. @param is The stream to read from.
  70. @param ec
  71. @param sp
  72. @param opt
  73. */
  74. BOOST_JSON_DECL
  75. value
  76. parse(
  77. std::istream& is,
  78. system::error_code& ec,
  79. storage_ptr sp = {},
  80. parse_options const& opt = {});
  81. /// Overload
  82. BOOST_JSON_DECL
  83. value
  84. parse(
  85. std::istream& is,
  86. std::error_code& ec,
  87. storage_ptr sp = {},
  88. parse_options const& opt = {});
  89. /// Overload
  90. BOOST_JSON_DECL
  91. value
  92. parse(
  93. std::istream& is,
  94. storage_ptr sp = {},
  95. parse_options const& opt = {});
  96. /// @}
  97. } // namespace json
  98. } // namespace boost
  99. #endif