Skip to content

Commit 2cb16b3

Browse files
authored
allowBom -> skipBom (open-source-parsers#1162)
1 parent 83946a2 commit 2cb16b3

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/lib_json/json_reader.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ class OurFeatures {
871871
bool failIfExtra_;
872872
bool rejectDupKeys_;
873873
bool allowSpecialFloats_;
874-
bool allowBom_;
874+
bool skipBom_;
875875
size_t stackLimit_;
876876
}; // OurFeatures
877877

@@ -940,7 +940,7 @@ class OurReader {
940940

941941
bool readToken(Token& token);
942942
void skipSpaces();
943-
void skipBom(bool allowBom);
943+
void skipBom(bool skipBom);
944944
bool match(const Char* pattern, int patternLength);
945945
bool readComment();
946946
bool readCStyleComment(bool* containsNewLineResult);
@@ -1025,7 +1025,7 @@ bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
10251025
nodes_.push(&root);
10261026

10271027
// skip byte order mark if it exists at the beginning of the UTF-8 text.
1028-
skipBom(features_.allowBom_);
1028+
skipBom(features_.skipBom_);
10291029
bool successful = readValue();
10301030
nodes_.pop();
10311031
Token token;
@@ -1272,10 +1272,9 @@ void OurReader::skipSpaces() {
12721272
}
12731273
}
12741274

1275-
void OurReader::skipBom(bool allowBom) {
1276-
// If BOM is not allowed, then skip it.
1277-
// The default value is: false
1278-
if (!allowBom) {
1275+
void OurReader::skipBom(bool skipBom) {
1276+
// The default behavior is to skip BOM.
1277+
if (skipBom) {
12791278
if (strncmp(begin_, "\xEF\xBB\xBF", 3) == 0) {
12801279
begin_ += 3;
12811280
current_ = begin_;
@@ -1900,7 +1899,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
19001899
features.failIfExtra_ = settings_["failIfExtra"].asBool();
19011900
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
19021901
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
1903-
features.allowBom_ = settings_["allowBom"].asBool();
1902+
features.skipBom_ = settings_["skipBom"].asBool();
19041903
return new OurCharReader(collectComments, features);
19051904
}
19061905
static void getValidReaderKeys(std::set<String>* valid_keys) {
@@ -1916,7 +1915,7 @@ static void getValidReaderKeys(std::set<String>* valid_keys) {
19161915
valid_keys->insert("failIfExtra");
19171916
valid_keys->insert("rejectDupKeys");
19181917
valid_keys->insert("allowSpecialFloats");
1919-
valid_keys->insert("allowBom");
1918+
valid_keys->insert("skipBom");
19201919
}
19211920
bool CharReaderBuilder::validate(Json::Value* invalid) const {
19221921
Json::Value my_invalid;
@@ -1951,7 +1950,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings) {
19511950
(*settings)["failIfExtra"] = true;
19521951
(*settings)["rejectDupKeys"] = true;
19531952
(*settings)["allowSpecialFloats"] = false;
1954-
(*settings)["allowBom"] = false;
1953+
(*settings)["skipBom"] = true;
19551954
//! [CharReaderBuilderStrictMode]
19561955
}
19571956
// static
@@ -1968,7 +1967,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
19681967
(*settings)["failIfExtra"] = false;
19691968
(*settings)["rejectDupKeys"] = false;
19701969
(*settings)["allowSpecialFloats"] = false;
1971-
(*settings)["allowBom"] = false;
1970+
(*settings)["skipBom"] = true;
19721971
//! [CharReaderBuilderDefaults]
19731972
}
19741973

src/test_lib_json/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,13 +3590,13 @@ JSONTEST_FIXTURE_LOCAL(BomTest, skipBom) {
35903590
JSONTEST_ASSERT(errs.empty());
35913591
JSONTEST_ASSERT_STRING_EQUAL(root["key"].asString(), "value");
35923592
}
3593-
JSONTEST_FIXTURE_LOCAL(BomTest, allowBom) {
3593+
JSONTEST_FIXTURE_LOCAL(BomTest, notSkipBom) {
35943594
const std::string with_bom = "\xEF\xBB\xBF{\"key\" : \"value\"}";
35953595
Json::Value root;
35963596
JSONCPP_STRING errs;
35973597
std::istringstream iss(with_bom);
35983598
Json::CharReaderBuilder b;
3599-
b.settings_["allowBom"] = true;
3599+
b.settings_["skipBom"] = false;
36003600
bool ok = parseFromStream(b, iss, &root, &errs);
36013601
// Detect the BOM, and failed on it.
36023602
JSONTEST_ASSERT(!ok);

0 commit comments

Comments
 (0)