| 181 | : features_(features) {} |
| 182 | |
| 183 | bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root, bool collectComments) { |
| 184 | if (!features_.allowComments_) { |
| 185 | collectComments = false; |
| 186 | } |
| 187 | |
| 188 | begin_ = beginDoc; |
| 189 | end_ = endDoc; |
| 190 | collectComments_ = collectComments; |
| 191 | current_ = begin_; |
| 192 | lastValueEnd_ = nullptr; |
| 193 | lastValue_ = nullptr; |
| 194 | commentsBefore_.clear(); |
| 195 | errors_.clear(); |
| 196 | while (!nodes_.empty()) |
| 197 | nodes_.pop(); |
| 198 | nodes_.push(&root); |
| 199 | |
| 200 | // skip byte order mark if it exists at the beginning of the UTF-8 text. |
| 201 | skipBom(features_.skipBom_); |
| 202 | bool successful = readValue(); |
| 203 | nodes_.pop(); |
| 204 | Token token; |
| 205 | readTokenSkippingComments(token); |
| 206 | if (features_.failIfExtra_ && (token.type_ != tokenEndOfStream)) { |
| 207 | addError("Extra non-whitespace after JSON value.", token); |
| 208 | return false; |
| 209 | } |
| 210 | if (collectComments_ && !commentsBefore_.empty()) |
| 211 | root.setComment(commentsBefore_, commentAfter); |
| 212 | if (features_.strictRoot_) { |
| 213 | if (!root.isArray() && !root.isObject()) { |
| 214 | // Set error location to start of doc, ideally should be first token found |
| 215 | // in doc |
| 216 | token.type_ = tokenError; |
| 217 | token.start_ = beginDoc; |
| 218 | token.end_ = endDoc; |
| 219 | addError("A valid JSON document must be either an array or an object value.", token); |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | return successful; |
| 224 | } |
| 225 | |
| 226 | bool OurReader::readValue() { |
| 227 | // To preserve the old behaviour we cast size_t to int. |
no test coverage detected