parser.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_PARSER_HPP
  10. #define BOOST_JSON_PARSER_HPP
  11. #include <boost/json/detail/config.hpp>
  12. #include <boost/json/basic_parser.hpp>
  13. #include <boost/json/storage_ptr.hpp>
  14. #include <boost/json/value.hpp>
  15. #include <boost/json/detail/handler.hpp>
  16. #include <type_traits>
  17. #include <cstddef>
  18. namespace boost {
  19. namespace json {
  20. //----------------------------------------------------------
  21. /** A DOM parser for JSON contained in a single buffer.
  22. This class is used to parse a JSON text contained in a
  23. single character buffer, into a @ref value container.
  24. @par Usage
  25. To use the parser first construct it, then optionally
  26. call @ref reset to specify a @ref storage_ptr to use
  27. for the resulting @ref value. Then call @ref write
  28. to parse a character buffer containing a complete
  29. JSON text. If the parse is successful, call @ref release
  30. to take ownership of the value:
  31. @code
  32. parser p; // construct a parser
  33. size_t n = p.write( "[1,2,3]" ); // parse a complete JSON text
  34. assert( n == 7 ); // all characters consumed
  35. value jv = p.release(); // take ownership of the value
  36. @endcode
  37. @par Extra Data
  38. When the character buffer provided as input contains
  39. additional data that is not part of the complete
  40. JSON text, an error is returned. The @ref write_some
  41. function is an alternative which allows the parse
  42. to finish early, without consuming all the characters
  43. in the buffer. This allows parsing of a buffer
  44. containing multiple individual JSON texts or containing
  45. different protocol data:
  46. @code
  47. parser p; // construct a parser
  48. size_t n = p.write_some( "[1,2,3] null" ); // parse a complete JSON text
  49. assert( n == 8 ); // only some characters consumed
  50. value jv = p.release(); // take ownership of the value
  51. @endcode
  52. @par Temporary Storage
  53. The parser may dynamically allocate temporary
  54. storage as needed to accommodate the nesting level
  55. of the JSON text being parsed. Temporary storage is
  56. first obtained from an optional, caller-owned
  57. buffer specified upon construction. When that
  58. is exhausted, the next allocation uses the
  59. `boost::container::pmr::memory_resource` passed to the constructor; if
  60. no such argument is specified, the default memory
  61. resource is used. Temporary storage is freed only
  62. when the parser is destroyed; The performance of
  63. parsing multiple JSON texts may be improved by reusing
  64. the same parser instance.
  65. \n
  66. It is important to note that the `boost::container::pmr::memory_resource`
  67. supplied upon construction is used for temporary
  68. storage only, and not for allocating the elements
  69. which make up the parsed value. That other memory
  70. resource is optionally supplied in each call
  71. to @ref reset.
  72. @par Duplicate Keys
  73. If there are object elements with duplicate keys;
  74. that is, if multiple elements in an object have
  75. keys that compare equal, only the last equivalent
  76. element will be inserted.
  77. @par Non-Standard JSON
  78. The @ref parse_options structure optionally
  79. provided upon construction is used to customize
  80. some parameters of the parser, including which
  81. non-standard JSON extensions should be allowed.
  82. A default-constructed parse options allows only
  83. standard JSON.
  84. @par Thread Safety
  85. Distinct instances may be accessed concurrently.
  86. Non-const member functions of a shared instance
  87. may not be called concurrently with any other
  88. member functions of that instance.
  89. @see
  90. @ref parse,
  91. @ref parse_options,
  92. @ref stream_parser.
  93. */
  94. class parser
  95. {
  96. basic_parser<detail::handler> p_;
  97. public:
  98. /// Copy constructor (deleted)
  99. parser(
  100. parser const&) = delete;
  101. /// Copy assignment (deleted)
  102. parser& operator=(
  103. parser const&) = delete;
  104. /** Destructor.
  105. All dynamically allocated memory, including
  106. any incomplete parsing results, is freed.
  107. @par Complexity
  108. Linear in the size of partial results
  109. @par Exception Safety
  110. No-throw guarantee.
  111. */
  112. ~parser() = default;
  113. /** Constructor.
  114. This constructs a new parser which first uses
  115. the caller-owned storage pointed to by `buffer`
  116. for temporary storage, falling back to the memory
  117. resource `sp` if needed. The parser will use the
  118. specified parsing options.
  119. \n
  120. The parsed value will use the default memory
  121. resource for storage. To use a different resource,
  122. call @ref reset after construction.
  123. @par Complexity
  124. Constant.
  125. @par Exception Safety
  126. No-throw guarantee.
  127. @param sp The memory resource to use for
  128. temporary storage after `buffer` is exhausted.
  129. @param opt The parsing options to use.
  130. @param buffer A pointer to valid memory of at least
  131. `size` bytes for the parser to use for temporary storage.
  132. Ownership is not transferred, the caller is responsible
  133. for ensuring the lifetime of the memory pointed to by
  134. `buffer` extends until the parser is destroyed.
  135. @param size The number of valid bytes in `buffer`.
  136. */
  137. BOOST_JSON_DECL
  138. parser(
  139. storage_ptr sp,
  140. parse_options const& opt,
  141. unsigned char* buffer,
  142. std::size_t size) noexcept;
  143. /** Constructor.
  144. This constructs a new parser which uses the default
  145. memory resource for temporary storage, and accepts
  146. only strict JSON.
  147. \n
  148. The parsed value will use the default memory
  149. resource for storage. To use a different resource,
  150. call @ref reset after construction.
  151. @par Complexity
  152. Constant.
  153. @par Exception Safety
  154. No-throw guarantee.
  155. */
  156. parser() noexcept
  157. : parser({}, {})
  158. {
  159. }
  160. /** Constructor.
  161. This constructs a new parser which uses the
  162. specified memory resource for temporary storage,
  163. and is configured to use the specified parsing
  164. options.
  165. \n
  166. The parsed value will use the default memory
  167. resource for storage. To use a different resource,
  168. call @ref reset after construction.
  169. @par Complexity
  170. Constant.
  171. @par Exception Safety
  172. No-throw guarantee.
  173. @param sp The memory resource to use for temporary storage.
  174. @param opt The parsing options to use.
  175. */
  176. BOOST_JSON_DECL
  177. parser(
  178. storage_ptr sp,
  179. parse_options const& opt) noexcept;
  180. /** Constructor.
  181. This constructs a new parser which uses the
  182. specified memory resource for temporary storage,
  183. and accepts only strict JSON.
  184. \n
  185. The parsed value will use the default memory
  186. resource for storage. To use a different resource,
  187. call @ref reset after construction.
  188. @par Complexity
  189. Constant.
  190. @par Exception Safety
  191. No-throw guarantee.
  192. @param sp The memory resource to use for temporary storage.
  193. */
  194. explicit
  195. parser(storage_ptr sp) noexcept
  196. : parser(std::move(sp), {})
  197. {
  198. }
  199. /** Constructor.
  200. This constructs a new parser which first uses the
  201. caller-owned storage `buffer` for temporary storage,
  202. falling back to the memory resource `sp` if needed.
  203. The parser will use the specified parsing options.
  204. \n
  205. The parsed value will use the default memory
  206. resource for storage. To use a different resource,
  207. call @ref reset after construction.
  208. @par Complexity
  209. Constant.
  210. @par Exception Safety
  211. No-throw guarantee.
  212. @param sp The memory resource to use for
  213. temporary storage after `buffer` is exhausted.
  214. @param opt The parsing options to use.
  215. @param buffer A buffer for the parser to use for
  216. temporary storage. Ownership is not transferred,
  217. the caller is responsible for ensuring the lifetime
  218. of `buffer` extends until the parser is destroyed.
  219. */
  220. template<std::size_t N>
  221. parser(
  222. storage_ptr sp,
  223. parse_options const& opt,
  224. unsigned char(&buffer)[N]) noexcept
  225. : parser(std::move(sp),
  226. opt, &buffer[0], N)
  227. {
  228. }
  229. #if defined(__cpp_lib_byte) || defined(BOOST_JSON_DOCS)
  230. /** Constructor.
  231. This constructs a new parser which first uses
  232. the caller-owned storage pointed to by `buffer`
  233. for temporary storage, falling back to the memory
  234. resource `sp` if needed. The parser will use the
  235. specified parsing options.
  236. \n
  237. The parsed value will use the default memory
  238. resource for storage. To use a different resource,
  239. call @ref reset after construction.
  240. @par Complexity
  241. Constant.
  242. @par Exception Safety
  243. No-throw guarantee.
  244. @param sp The memory resource to use for
  245. temporary storage after `buffer` is exhausted.
  246. @param opt The parsing options to use.
  247. @param buffer A pointer to valid memory of at least
  248. `size` bytes for the parser to use for temporary storage.
  249. Ownership is not transferred, the caller is responsible
  250. for ensuring the lifetime of the memory pointed to by
  251. `buffer` extends until the parser is destroyed.
  252. @param size The number of valid bytes in `buffer`.
  253. */
  254. parser(
  255. storage_ptr sp,
  256. parse_options const& opt,
  257. std::byte* buffer,
  258. std::size_t size) noexcept
  259. : parser(sp, opt, reinterpret_cast<
  260. unsigned char*>(buffer), size)
  261. {
  262. }
  263. /** Constructor.
  264. This constructs a new parser which first uses the
  265. caller-owned storage `buffer` for temporary storage,
  266. falling back to the memory resource `sp` if needed.
  267. The parser will use the specified parsing options.
  268. \n
  269. The parsed value will use the default memory
  270. resource for storage. To use a different resource,
  271. call @ref reset after construction.
  272. @par Complexity
  273. Constant.
  274. @par Exception Safety
  275. No-throw guarantee.
  276. @param sp The memory resource to use for
  277. temporary storage after `buffer` is exhausted.
  278. @param opt The parsing options to use.
  279. @param buffer A buffer for the parser to use for
  280. temporary storage. Ownership is not transferred,
  281. the caller is responsible for ensuring the lifetime
  282. of `buffer` extends until the parser is destroyed.
  283. */
  284. template<std::size_t N>
  285. parser(
  286. storage_ptr sp,
  287. parse_options const& opt,
  288. std::byte(&buffer)[N]) noexcept
  289. : parser(std::move(sp),
  290. opt, &buffer[0], N)
  291. {
  292. }
  293. #endif
  294. #ifndef BOOST_JSON_DOCS
  295. // Safety net for accidental buffer overflows
  296. template<std::size_t N>
  297. parser(
  298. storage_ptr sp,
  299. parse_options const& opt,
  300. unsigned char(&buffer)[N],
  301. std::size_t n) noexcept
  302. : parser(std::move(sp),
  303. opt, &buffer[0], n)
  304. {
  305. // If this goes off, check your parameters
  306. // closely, chances are you passed an array
  307. // thinking it was a pointer.
  308. BOOST_ASSERT(n <= N);
  309. }
  310. #ifdef __cpp_lib_byte
  311. // Safety net for accidental buffer overflows
  312. template<std::size_t N>
  313. parser(
  314. storage_ptr sp,
  315. parse_options const& opt,
  316. std::byte(&buffer)[N], std::size_t n) noexcept
  317. : parser(std::move(sp),
  318. opt, &buffer[0], n)
  319. {
  320. // If this goes off, check your parameters
  321. // closely, chances are you passed an array
  322. // thinking it was a pointer.
  323. BOOST_ASSERT(n <= N);
  324. }
  325. #endif
  326. #endif
  327. /** Reset the parser for a new JSON text.
  328. This function is used to reset the parser to
  329. prepare it for parsing a new complete JSON text.
  330. Any previous partial results are destroyed.
  331. @par Complexity
  332. Constant or linear in the size of any previous
  333. partial parsing results.
  334. @par Exception Safety
  335. No-throw guarantee.
  336. @param sp A pointer to the `boost::container::pmr::memory_resource` to
  337. use for the resulting @ref value. The parser will acquire shared
  338. ownership.
  339. */
  340. BOOST_JSON_DECL
  341. void
  342. reset(storage_ptr sp = {}) noexcept;
  343. /** Parse a buffer containing a complete JSON text.
  344. This function parses a complete JSON text contained
  345. in the specified character buffer. Additional
  346. characters past the end of the complete JSON text
  347. are ignored. The function returns the actual
  348. number of characters parsed, which may be less
  349. than the size of the input. This allows parsing
  350. of a buffer containing multiple individual JSON texts
  351. or containing different protocol data:
  352. @par Example
  353. @code
  354. parser p; // construct a parser
  355. size_t n = p.write_some( "[1,2,3] null" ); // parse a complete JSON text
  356. assert( n == 8 ); // only some characters consumed
  357. value jv = p.release(); // take ownership of the value
  358. @endcode
  359. @par Complexity
  360. Linear in `size`.
  361. @par Exception Safety
  362. Basic guarantee.
  363. Calls to `memory_resource::allocate` may throw.
  364. Upon error or exception, subsequent calls will
  365. fail until @ref reset is called to parse a new JSON text.
  366. @return The number of characters consumed from
  367. the buffer.
  368. @param data A pointer to a buffer of `size`
  369. characters to parse.
  370. @param size The number of characters pointed to
  371. by `data`.
  372. @param ec Set to the error, if any occurred.
  373. */
  374. /** @{ */
  375. BOOST_JSON_DECL
  376. std::size_t
  377. write_some(
  378. char const* data,
  379. std::size_t size,
  380. system::error_code& ec);
  381. BOOST_JSON_DECL
  382. std::size_t
  383. write_some(
  384. char const* data,
  385. std::size_t size,
  386. std::error_code& ec);
  387. /** @} */
  388. /** Parse a buffer containing a complete JSON text.
  389. This function parses a complete JSON text contained
  390. in the specified character buffer. Additional
  391. characters past the end of the complete JSON text
  392. are ignored. The function returns the actual
  393. number of characters parsed, which may be less
  394. than the size of the input. This allows parsing
  395. of a buffer containing multiple individual JSON texts
  396. or containing different protocol data:
  397. @par Example
  398. @code
  399. parser p; // construct a parser
  400. size_t n = p.write_some( "[1,2,3] null" ); // parse a complete JSON text
  401. assert( n == 8 ); // only some characters consumed
  402. value jv = p.release(); // take ownership of the value
  403. @endcode
  404. @par Complexity
  405. Linear in `size`.
  406. @par Exception Safety
  407. Basic guarantee.
  408. Calls to `memory_resource::allocate` may throw.
  409. Upon error or exception, subsequent calls will
  410. fail until @ref reset is called to parse a new JSON text.
  411. @return The number of characters consumed from
  412. the buffer.
  413. @param data A pointer to a buffer of `size`
  414. characters to parse.
  415. @param size The number of characters pointed to
  416. by `data`.
  417. @throw `boost::system::system_error` Thrown on error.
  418. */
  419. BOOST_JSON_DECL
  420. std::size_t
  421. write_some(
  422. char const* data,
  423. std::size_t size);
  424. /** Parse a buffer containing a complete JSON text.
  425. This function parses a complete JSON text contained
  426. in the specified character buffer. Additional
  427. characters past the end of the complete JSON text
  428. are ignored. The function returns the actual
  429. number of characters parsed, which may be less
  430. than the size of the input. This allows parsing
  431. of a buffer containing multiple individual JSON texts
  432. or containing different protocol data:
  433. @par Example
  434. @code
  435. parser p; // construct a parser
  436. size_t n = p.write_some( "[1,2,3] null" ); // parse a complete JSON text
  437. assert( n == 8 ); // only some characters consumed
  438. value jv = p.release(); // take ownership of the value
  439. @endcode
  440. @par Complexity
  441. Linear in `size`.
  442. @par Exception Safety
  443. Basic guarantee.
  444. Calls to `memory_resource::allocate` may throw.
  445. Upon error or exception, subsequent calls will
  446. fail until @ref reset is called to parse a new JSON text.
  447. @return The number of characters consumed from
  448. the buffer.
  449. @param s The character string to parse.
  450. @param ec Set to the error, if any occurred.
  451. */
  452. /** @{ */
  453. std::size_t
  454. write_some(
  455. string_view s,
  456. system::error_code& ec)
  457. {
  458. return write_some(
  459. s.data(), s.size(), ec);
  460. }
  461. std::size_t
  462. write_some(
  463. string_view s,
  464. std::error_code& ec)
  465. {
  466. return write_some(
  467. s.data(), s.size(), ec);
  468. }
  469. /** @} */
  470. /** Parse a buffer containing a complete JSON text.
  471. This function parses a complete JSON text contained
  472. in the specified character buffer. Additional
  473. characters past the end of the complete JSON text
  474. are ignored. The function returns the actual
  475. number of characters parsed, which may be less
  476. than the size of the input. This allows parsing
  477. of a buffer containing multiple individual JSON texts
  478. or containing different protocol data:
  479. @par Example
  480. @code
  481. parser p; // construct a parser
  482. size_t n = p.write_some( "[1,2,3] null" ); // parse a complete JSON text
  483. assert( n == 8 ); // only some characters consumed
  484. value jv = p.release(); // take ownership of the value
  485. @endcode
  486. @par Complexity
  487. Linear in `size`.
  488. @par Exception Safety
  489. Basic guarantee.
  490. Calls to `memory_resource::allocate` may throw.
  491. Upon error or exception, subsequent calls will
  492. fail until @ref reset is called to parse a new JSON text.
  493. @return The number of characters consumed from
  494. the buffer.
  495. @param s The character string to parse.
  496. @throw `boost::system::system_error` Thrown on error.
  497. */
  498. std::size_t
  499. write_some(
  500. string_view s)
  501. {
  502. return write_some(
  503. s.data(), s.size());
  504. }
  505. /** Parse a buffer containing a complete JSON text.
  506. This function parses a complete JSON text contained
  507. in the specified character buffer. The entire
  508. buffer must be consumed; if there are additional
  509. characters past the end of the complete JSON text,
  510. the parse fails and an error is returned.
  511. @par Example
  512. @code
  513. parser p; // construct a parser
  514. size_t n = p.write( "[1,2,3]" ); // parse a complete JSON text
  515. assert( n == 7 ); // all characters consumed
  516. value jv = p.release(); // take ownership of the value
  517. @endcode
  518. @par Complexity
  519. Linear in `size`.
  520. @par Exception Safety
  521. Basic guarantee.
  522. Calls to `memory_resource::allocate` may throw.
  523. Upon error or exception, subsequent calls will
  524. fail until @ref reset is called to parse a new JSON text.
  525. @return The number of characters consumed from
  526. the buffer.
  527. @param data A pointer to a buffer of `size`
  528. characters to parse.
  529. @param size The number of characters pointed to
  530. by `data`.
  531. @param ec Set to the error, if any occurred.
  532. */
  533. /** @{ */
  534. BOOST_JSON_DECL
  535. std::size_t
  536. write(
  537. char const* data,
  538. std::size_t size,
  539. system::error_code& ec);
  540. BOOST_JSON_DECL
  541. std::size_t
  542. write(
  543. char const* data,
  544. std::size_t size,
  545. std::error_code& ec);
  546. /** @} */
  547. /** Parse a buffer containing a complete JSON text.
  548. This function parses a complete JSON text contained
  549. in the specified character buffer. The entire
  550. buffer must be consumed; if there are additional
  551. characters past the end of the complete JSON text,
  552. the parse fails and an error is returned.
  553. @par Example
  554. @code
  555. parser p; // construct a parser
  556. size_t n = p.write( "[1,2,3]" ); // parse a complete JSON text
  557. assert( n == 7 ); // all characters consumed
  558. value jv = p.release(); // take ownership of the value
  559. @endcode
  560. @par Complexity
  561. Linear in `size`.
  562. @par Exception Safety
  563. Basic guarantee.
  564. Calls to `memory_resource::allocate` may throw.
  565. Upon error or exception, subsequent calls will
  566. fail until @ref reset is called to parse a new JSON text.
  567. @return The number of characters consumed from
  568. the buffer.
  569. @param data A pointer to a buffer of `size`
  570. characters to parse.
  571. @param size The number of characters pointed to
  572. by `data`.
  573. @throw `boost::system::system_error` Thrown on error.
  574. */
  575. BOOST_JSON_DECL
  576. std::size_t
  577. write(
  578. char const* data,
  579. std::size_t size);
  580. /** Parse a buffer containing a complete JSON text.
  581. This function parses a complete JSON text contained
  582. in the specified character buffer. The entire
  583. buffer must be consumed; if there are additional
  584. characters past the end of the complete JSON text,
  585. the parse fails and an error is returned.
  586. @par Example
  587. @code
  588. parser p; // construct a parser
  589. size_t n = p.write( "[1,2,3]" ); // parse a complete JSON text
  590. assert( n == 7 ); // all characters consumed
  591. value jv = p.release(); // take ownership of the value
  592. @endcode
  593. @par Complexity
  594. Linear in `size`.
  595. @par Exception Safety
  596. Basic guarantee.
  597. Calls to `memory_resource::allocate` may throw.
  598. Upon error or exception, subsequent calls will
  599. fail until @ref reset is called to parse a new JSON text.
  600. @return The number of characters consumed from
  601. the buffer.
  602. @param s The character string to parse.
  603. @param ec Set to the error, if any occurred.
  604. */
  605. /** @{ */
  606. std::size_t
  607. write(
  608. string_view s,
  609. system::error_code& ec)
  610. {
  611. return write(
  612. s.data(), s.size(), ec);
  613. }
  614. std::size_t
  615. write(
  616. string_view s,
  617. std::error_code& ec)
  618. {
  619. return write(
  620. s.data(), s.size(), ec);
  621. }
  622. /** @} */
  623. /** Parse a buffer containing a complete JSON text.
  624. This function parses a complete JSON text contained
  625. in the specified character buffer. The entire
  626. buffer must be consumed; if there are additional
  627. characters past the end of the complete JSON text,
  628. the parse fails and an error is returned.
  629. @par Example
  630. @code
  631. parser p; // construct a parser
  632. size_t n = p.write( "[1,2,3]" ); // parse a complete JSON text
  633. assert( n == 7 ); // all characters consumed
  634. value jv = p.release(); // take ownership of the value
  635. @endcode
  636. @par Complexity
  637. Linear in `size`.
  638. @par Exception Safety
  639. Basic guarantee.
  640. Calls to `memory_resource::allocate` may throw.
  641. Upon error or exception, subsequent calls will
  642. fail until @ref reset is called to parse a new JSON text.
  643. @return The number of characters consumed from
  644. the buffer.
  645. @param s The character string to parse.
  646. @throw `boost::system::system_error` Thrown on error.
  647. */
  648. std::size_t
  649. write(
  650. string_view s)
  651. {
  652. return write(
  653. s.data(), s.size());
  654. }
  655. /** Return the parsed JSON text as a @ref value.
  656. This returns the parsed value, or throws
  657. an exception if the parsing is incomplete or
  658. failed. It is necessary to call @ref reset
  659. after calling this function in order to parse
  660. another JSON text.
  661. @par Complexity
  662. Constant.
  663. @return The parsed value. Ownership of this
  664. value is transferred to the caller.
  665. @throw `boost::system::system_error` Thrown on failure.
  666. */
  667. BOOST_JSON_DECL
  668. value
  669. release();
  670. };
  671. } // namespace json
  672. } // namespace boost
  673. #endif