@@ -909,12 +909,12 @@ bool Reader::good() const {
909
909
class OurFeatures {
910
910
public:
911
911
static OurFeatures all ();
912
- static OurFeatures strictMode ();
913
912
OurFeatures ();
914
913
bool allowComments_;
915
914
bool strictRoot_;
916
915
bool allowDroppedNullPlaceholders_;
917
916
bool allowNumericKeys_;
917
+ bool allowSingleQuotes_;
918
918
bool failIfExtra_;
919
919
int stackLimit_;
920
920
}; // OurFeatures
@@ -923,20 +923,15 @@ class OurFeatures {
923
923
// ////////////////////////////////
924
924
925
925
OurFeatures::OurFeatures ()
926
- : allowComments_(true ), strictRoot_(false ),
927
- allowDroppedNullPlaceholders_(false ), allowNumericKeys_(false ) {}
926
+ : allowComments_(true ), strictRoot_(false )
927
+ , allowDroppedNullPlaceholders_(false ), allowNumericKeys_(false )
928
+ , allowSingleQuotes_(false )
929
+ , failIfExtra_(false )
930
+ {
931
+ }
928
932
929
933
OurFeatures OurFeatures::all () { return OurFeatures (); }
930
934
931
- OurFeatures OurFeatures::strictMode () {
932
- OurFeatures features;
933
- features.allowComments_ = false ;
934
- features.strictRoot_ = true ;
935
- features.allowDroppedNullPlaceholders_ = false ;
936
- features.allowNumericKeys_ = false ;
937
- return features;
938
- }
939
-
940
935
// Implementation of class Reader
941
936
// ////////////////////////////////
942
937
@@ -1006,6 +1001,7 @@ class OurReader {
1006
1001
bool readCStyleComment ();
1007
1002
bool readCppStyleComment ();
1008
1003
bool readString ();
1004
+ bool readStringSingleQuote ();
1009
1005
void readNumber ();
1010
1006
bool readValue ();
1011
1007
bool readObject (Token& token);
@@ -1220,6 +1216,12 @@ bool OurReader::readToken(Token& token) {
1220
1216
token.type_ = tokenString;
1221
1217
ok = readString ();
1222
1218
break ;
1219
+ case ' \' ' :
1220
+ if (features_.allowSingleQuotes_ ) {
1221
+ token.type_ = tokenString;
1222
+ ok = readStringSingleQuote ();
1223
+ break ;
1224
+ } // else continue
1223
1225
case ' /' :
1224
1226
token.type_ = tokenComment;
1225
1227
ok = readComment ();
@@ -1371,7 +1373,6 @@ void OurReader::readNumber() {
1371
1373
c = (current_ = p) < end_ ? *p++ : 0 ;
1372
1374
}
1373
1375
}
1374
-
1375
1376
bool OurReader::readString () {
1376
1377
Char c = 0 ;
1377
1378
while (current_ != end_) {
@@ -1384,6 +1385,19 @@ bool OurReader::readString() {
1384
1385
return c == ' "' ;
1385
1386
}
1386
1387
1388
+
1389
+ bool OurReader::readStringSingleQuote () {
1390
+ Char c = 0 ;
1391
+ while (current_ != end_) {
1392
+ c = getNextChar ();
1393
+ if (c == ' \\ ' )
1394
+ getNextChar ();
1395
+ else if (c == ' \' ' )
1396
+ break ;
1397
+ }
1398
+ return c == ' \' ' ;
1399
+ }
1400
+
1387
1401
bool OurReader::readObject (Token& tokenStart) {
1388
1402
Token tokenName;
1389
1403
std::string name;
@@ -1878,6 +1892,7 @@ CharReader* CharReaderBuilder::newCharReader() const
1878
1892
features.strictRoot_ = settings_[" strictRoot" ].asBool ();
1879
1893
features.allowDroppedNullPlaceholders_ = settings_[" allowDroppedNullPlaceholders" ].asBool ();
1880
1894
features.allowNumericKeys_ = settings_[" allowNumericKeys" ].asBool ();
1895
+ features.allowSingleQuotes_ = settings_[" allowSingleQuotes" ].asBool ();
1881
1896
features.stackLimit_ = settings_[" stackLimit" ].asInt ();
1882
1897
features.failIfExtra_ = settings_[" failIfExtra" ].asBool ();
1883
1898
return new OurCharReader (collectComments, features);
@@ -1890,6 +1905,7 @@ static void getValidReaderKeys(std::set<std::string>* valid_keys)
1890
1905
valid_keys->insert (" strictRoot" );
1891
1906
valid_keys->insert (" allowDroppedNullPlaceholders" );
1892
1907
valid_keys->insert (" allowNumericKeys" );
1908
+ valid_keys->insert (" allowSingleQuotes" );
1893
1909
valid_keys->insert (" stackLimit" );
1894
1910
valid_keys->insert (" failIfExtra" );
1895
1911
}
@@ -1919,6 +1935,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings)
1919
1935
(*settings)[" strictRoot" ] = true ;
1920
1936
(*settings)[" allowDroppedNullPlaceholders" ] = false ;
1921
1937
(*settings)[" allowNumericKeys" ] = false ;
1938
+ (*settings)[" allowSingleQuotes" ] = false ;
1922
1939
(*settings)[" failIfExtra" ] = true ;
1923
1940
// ! [CharReaderBuilderStrictMode]
1924
1941
}
@@ -1931,6 +1948,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings)
1931
1948
(*settings)[" strictRoot" ] = false ;
1932
1949
(*settings)[" allowDroppedNullPlaceholders" ] = false ;
1933
1950
(*settings)[" allowNumericKeys" ] = false ;
1951
+ (*settings)[" allowSingleQuotes" ] = false ;
1934
1952
(*settings)[" stackLimit" ] = 1000 ;
1935
1953
(*settings)[" failIfExtra" ] = false ;
1936
1954
// ! [CharReaderBuilderDefaults]
0 commit comments