MCPcopy Create free account
hub / github.com/boostorg/json / read_jsons

Function read_jsons

test/doc_parsing.cpp:182–214  ·  view source on GitHub ↗

tag::doc_parsing_14[]

Source from the content-addressed store, hash-verified

180
181// tag::doc_parsing_14[]
182std::vector<value> read_jsons( std::istream& is, boost::system::error_code& ec )
183{
184 std::vector< value > jvs;
185 stream_parser p;
186 std::string line;
187 std::size_t n = 0;
188 while( true )
189 {
190 if( n == line.size() )
191 {
192 if( !std::getline( is, line ) )
193 break;
194 n = 0;
195 }
196
197 n += p.write_some( line.data() + n, line.size() - n, ec );
198
199 if( p.done() )
200 {
201 jvs.push_back( p.release() );
202 p.reset();
203 }
204 }
205 if( !p.done() ) // this part handles the cases when the last JSON text in
206 { // the input is either incomplete or doesn't have a marker
207 p.finish(ec); // for end of the value (e.g. it is a number)
208 if( ec.failed() )
209 return jvs;
210 jvs.push_back( p.release() );
211 }
212
213 return jvs;
214}
215// end::doc_parsing_14[]
216
217//----------------------------------------------------------

Callers 1

runMethod · 0.85

Calls 8

finishMethod · 0.80
sizeMethod · 0.45
write_someMethod · 0.45
dataMethod · 0.45
doneMethod · 0.45
push_backMethod · 0.45
releaseMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected