Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit 7789ef3d8d.
PrevUpHomeNext
stream_parser::write (4 of 6 overloads)

Parse a buffer containing all or part of a complete JSON text.

Synopsis
std::size_t
write(
    string_view s,
    std::error_code& ec);
Description

This function parses a all or part of a JSON text contained in the specified character buffer. The entire buffer must be consumed; if there are additional characters past the end of the complete JSON text, the parse fails and an error is returned.

Example
stream_parser p;                                // construct a parser
std::size_t n;                                  // number of characters used
n = p.write( "[1,2" );                          // parse some of the JSON text
assert( n == 4 );                               // all characters consumed
n = p.write( "3,4]" );                          // parse the rest of the JSON text
assert( n == 4 );                               // all characters consumed
value jv = p.release();                         // take ownership of the value
Remarks

To indicate there are no more character buffers, such as when done returns false after writing, call finish.

Complexity

Linear in size.

Exception Safety

Basic guarantee. Calls to memory_resource::allocate may throw. Upon error or exception, subsequent calls will fail until reset is called to parse a new JSON text.

Return Value

The number of characters consumed from the buffer.

Parameters

Name

Description

s

The character string to parse.

ec

Set to the error, if any occurred.


PrevUpHomeNext