Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement wrapper around XML parser into an svn_stream_t.
The current XML parser API needs a bunch of function to invoke. Firstly it requires to create a parser using svn_xml_make_parser(), then push the chunks using svn_xml_parse(), and finally close/free/dispose the parser using svn_xml_free_parser(). This API sometimes over complicate the usage or may require some additional work for the users. This commit introduces a wrapper into an svn_stream_t. It may help the users to create a parser from any kind of stream or a file. Use code like this to parse an XML file, assuming callbacks implemented separately: [[[ svn_stream_t *fstream; svn_stream_t *xml_stream; svn_xml_parser_t *xml_parser; SVN_ERR(svn_stream_open_readonly(&fstream, fpath, pool, pool)); xml_parser = svn_xml_make_parser(baton, start_handler, end_handler, data_handler, pool); xml_stream = svn_xml_make_parse_stream(xml_parser, pool); SVN_ERR(svn_stream_copy3(fstream, xml_stream, NULL, NULL, pool)); /* svn_stream_copy3() automatically closes fstream and xml_stream */ ]]] ...This makes it simpler a lot, due to a unified stream. Also adding the declaration of the svn_xml_make_parse_stream() function with its docstring to the log-message: [[[ /** Create a stream that wraps the XML parser described at @A parser. * * The stream produced will implement 'write' and 'close' methods. It * will push the data to the parser on write operation, and flush it on * close. * * This stream can be used as a generic writable stream, so the callers * may pipe any data there, for example, using the svn_stream_copy3 * function, in case of a file source. * * @SInCE New in 1.15. */ svn_stream_t * svn_xml_make_parse_stream(svn_xml_parser_t *parser, apr_pool_t *result_pool); ]]] Currently there are no usages of this function, only the tests have been introduced. In the feature, this could be used for the xpatch parser. This stream would have been implemented in a separate file, xml_stream.c, as part of the libsvn_subr API. * subversion/include/svn_xml.h (includes): Add 'svn_io.h' for svn_stream_t. (svn_xml_make_parse_stream): Declare function. * subversion/libsvn_subr/xml_stream.c: New file. (xml_stream_baton_t): New baton. (xml_stream_write, xml_stream_close): New functions, implementing svn_stream_t interface. (svn_xml_make_parse_stream): Implement function. * subversion/tests/libsvn_subr/xml-test.c (test_xml_parse_stream, test_xml_parse_stream_invalid_xml): New tests. (test_funcs): Run these tests. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1922567 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information