mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-26 10:41:03 +08:00
allowBom -> skipBom (#1162)
This commit is contained in:
parent
83946a28db
commit
2cb16b35dc
@ -871,7 +871,7 @@ public:
|
||||
bool failIfExtra_;
|
||||
bool rejectDupKeys_;
|
||||
bool allowSpecialFloats_;
|
||||
bool allowBom_;
|
||||
bool skipBom_;
|
||||
size_t stackLimit_;
|
||||
}; // OurFeatures
|
||||
|
||||
@ -940,7 +940,7 @@ private:
|
||||
|
||||
bool readToken(Token& token);
|
||||
void skipSpaces();
|
||||
void skipBom(bool allowBom);
|
||||
void skipBom(bool skipBom);
|
||||
bool match(const Char* pattern, int patternLength);
|
||||
bool readComment();
|
||||
bool readCStyleComment(bool* containsNewLineResult);
|
||||
@ -1025,7 +1025,7 @@ bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
|
||||
nodes_.push(&root);
|
||||
|
||||
// skip byte order mark if it exists at the beginning of the UTF-8 text.
|
||||
skipBom(features_.allowBom_);
|
||||
skipBom(features_.skipBom_);
|
||||
bool successful = readValue();
|
||||
nodes_.pop();
|
||||
Token token;
|
||||
@ -1272,10 +1272,9 @@ void OurReader::skipSpaces() {
|
||||
}
|
||||
}
|
||||
|
||||
void OurReader::skipBom(bool allowBom) {
|
||||
// If BOM is not allowed, then skip it.
|
||||
// The default value is: false
|
||||
if (!allowBom) {
|
||||
void OurReader::skipBom(bool skipBom) {
|
||||
// The default behavior is to skip BOM.
|
||||
if (skipBom) {
|
||||
if (strncmp(begin_, "\xEF\xBB\xBF", 3) == 0) {
|
||||
begin_ += 3;
|
||||
current_ = begin_;
|
||||
@ -1900,7 +1899,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
|
||||
features.failIfExtra_ = settings_["failIfExtra"].asBool();
|
||||
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
|
||||
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
|
||||
features.allowBom_ = settings_["allowBom"].asBool();
|
||||
features.skipBom_ = settings_["skipBom"].asBool();
|
||||
return new OurCharReader(collectComments, features);
|
||||
}
|
||||
static void getValidReaderKeys(std::set<String>* valid_keys) {
|
||||
@ -1916,7 +1915,7 @@ static void getValidReaderKeys(std::set<String>* valid_keys) {
|
||||
valid_keys->insert("failIfExtra");
|
||||
valid_keys->insert("rejectDupKeys");
|
||||
valid_keys->insert("allowSpecialFloats");
|
||||
valid_keys->insert("allowBom");
|
||||
valid_keys->insert("skipBom");
|
||||
}
|
||||
bool CharReaderBuilder::validate(Json::Value* invalid) const {
|
||||
Json::Value my_invalid;
|
||||
@ -1951,7 +1950,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings) {
|
||||
(*settings)["failIfExtra"] = true;
|
||||
(*settings)["rejectDupKeys"] = true;
|
||||
(*settings)["allowSpecialFloats"] = false;
|
||||
(*settings)["allowBom"] = false;
|
||||
(*settings)["skipBom"] = true;
|
||||
//! [CharReaderBuilderStrictMode]
|
||||
}
|
||||
// static
|
||||
@ -1968,7 +1967,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
|
||||
(*settings)["failIfExtra"] = false;
|
||||
(*settings)["rejectDupKeys"] = false;
|
||||
(*settings)["allowSpecialFloats"] = false;
|
||||
(*settings)["allowBom"] = false;
|
||||
(*settings)["skipBom"] = true;
|
||||
//! [CharReaderBuilderDefaults]
|
||||
}
|
||||
|
||||
|
@ -3590,13 +3590,13 @@ JSONTEST_FIXTURE_LOCAL(BomTest, skipBom) {
|
||||
JSONTEST_ASSERT(errs.empty());
|
||||
JSONTEST_ASSERT_STRING_EQUAL(root["key"].asString(), "value");
|
||||
}
|
||||
JSONTEST_FIXTURE_LOCAL(BomTest, allowBom) {
|
||||
JSONTEST_FIXTURE_LOCAL(BomTest, notSkipBom) {
|
||||
const std::string with_bom = "\xEF\xBB\xBF{\"key\" : \"value\"}";
|
||||
Json::Value root;
|
||||
JSONCPP_STRING errs;
|
||||
std::istringstream iss(with_bom);
|
||||
Json::CharReaderBuilder b;
|
||||
b.settings_["allowBom"] = true;
|
||||
b.settings_["skipBom"] = false;
|
||||
bool ok = parseFromStream(b, iss, &root, &errs);
|
||||
// Detect the BOM, and failed on it.
|
||||
JSONTEST_ASSERT(!ok);
|
||||
|
Loading…
x
Reference in New Issue
Block a user