diff options
author | 2021-10-05 03:34:45 +1100 | |
---|---|---|
committer | 2021-10-05 03:34:45 +1100 | |
commit | aeb9eae87469e67bc6a91caf3840c34c11d959fc (patch) | |
tree | 45bffedf374dbce47caca633ad7bda547592e6c9 /src/lib/util/xmlfile.cpp | |
parent | 33723892a3f06e678d817b36aef84364c32848ec (diff) |
util: Further API cleanups: (#8661)
* Turned `core_file` into an implementation of `random_read_write`.
* Turned PNG errors into a standard error category.
* Added a helper for generating what look like derived classes on-the-fly.
Diffstat (limited to 'src/lib/util/xmlfile.cpp')
-rw-r--r-- | src/lib/util/xmlfile.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/lib/util/xmlfile.cpp b/src/lib/util/xmlfile.cpp index adcf56a15c7..b290f6e5381 100644 --- a/src/lib/util/xmlfile.cpp +++ b/src/lib/util/xmlfile.cpp @@ -47,7 +47,8 @@ void write_escaped(core_file &file, std::string const &str) std::string::size_type const found = str.find_first_of("\"&<>", pos); if (found != std::string::npos) { - file.write(&str[pos], found - pos); + std::size_t written; + file.write(&str[pos], found - pos, written); switch (str[found]) { case '"': file.puts("""); pos = found + 1; break; @@ -59,7 +60,8 @@ void write_escaped(core_file &file, std::string const &str) } else { - file.write(&str[pos], str.size() - pos); + std::size_t written; + file.write(&str[pos], str.size() - pos, written); pos = found; } } @@ -118,28 +120,28 @@ file::ptr file::create() // read - parse an XML file into its nodes //------------------------------------------------- -file::ptr file::read(util::core_file &file, parse_options const *opts) +file::ptr file::read(read_stream &file, parse_options const *opts) { - parse_info info; - int done; - // set up the parser + parse_info info; if (!expat_setup_parser(info, opts)) return ptr(); // loop through the file and parse it + bool done; do { char tempbuf[TEMP_BUFFER_SIZE]; // read as much as we can - int bytes = file.read(tempbuf, sizeof(tempbuf)); - done = file.eof(); + size_t bytes; + file.read(tempbuf, sizeof(tempbuf), bytes); // TODO: better error handling + done = !bytes; // parse the data if (XML_Parse(info.parser, tempbuf, bytes, done) == XML_STATUS_ERROR) { - if (opts != nullptr && opts->error != nullptr) + if (opts && opts->error) { opts->error->error_message = XML_ErrorString(XML_GetErrorCode(info.parser)); opts->error->error_line = XML_GetCurrentLineNumber(info.parser); |