MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / ParseFile

Method ParseFile

lib/mdflib/mdflib/src/expatxml.cpp:112–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112bool ExpatXml::ParseFile() {
113 Reset();
114
115 std::FILE *file = nullptr;
116 Platform::fileopen(&file, filename_.c_str(), "r");
117 if (file == nullptr) {
118 return false;
119 }
120
121 ExpatParser p(this);
122 std::array<char, 1024> buffer{};
123 bool ok = true;
124 for (size_t reads = fread(buffer.data(), 1, buffer.size(), file); reads > 0;
125 reads = fread(buffer.data(), 1, buffer.size(), file)) {
126 const auto ret = p.Parse(buffer.data(), reads, reads == 0);
127 if (ret != XML_STATUS_OK) {
128 const auto line = XML_GetCurrentLineNumber(p.parser_);
129 const auto column = XML_GetCurrentColumnNumber(p.parser_);
130 const auto error = XML_GetErrorCode(p.parser_);
131 const auto *error_text = XML_ErrorString(error);
132 MDF_ERROR() << "XML parser error. Line: " << line
133 << ", Column: " << column << ", Error: " << error_text
134 << ", File: " << filename_;
135 ok = false;
136 break;
137 }
138 }
139 if (ok && !std::feof(file)) {
140 MDF_ERROR() << "XML file error. Error: Not entire file was read. File: "
141 << filename_;
142 ok = false;
143 }
144
145 std::fclose(file);
146 return ok;
147}
148
149bool ExpatXml::ParseString(const std::string &input) {
150 Reset();

Callers

nothing calls this directly

Calls 4

fileopenFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45
ParseMethod · 0.45

Tested by

no test coverage detected