Skip to content

Commit

Permalink
Removed unused settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Chlumsky committed Mar 24, 2023
1 parent 9c32dd7 commit c389677
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 142 deletions.
3 changes: 0 additions & 3 deletions configuration-parser-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
],
"settings": {
"jsonIOMode": "NULL_TERMINATED_STRING",
"keyFormat": "ANY",
"enumFormat": "ANY",
"noThrow": false,
"verboseErrors": true,
"strictSyntaxCheck": true,
"checkMissingKeys": false,
"checkRepeatingKeys": false,
Expand Down
182 changes: 55 additions & 127 deletions generated/ConfigurationParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,56 +300,22 @@ void ConfigurationParser::parseStdVectorConfigurationGeneratorDef(std::vector<Co
throw Error::JSON_SYNTAX_ERROR;
}

void ConfigurationParser::parseNameFormat(NameFormat &value) {
void ConfigurationParser::parseBool(bool &value) {
skipWhitespace();
if (cur[0] == 'f' && cur[1] == 'a' && cur[2] == 'l' && cur[3] == 's' && cur[4] == 'e' && !isAlphanumeric(cur[5]) && cur[5] != '_' && (cur += 5, true))
value = false;
else if (cur[0] == 't' && cur[1] == 'r' && cur[2] == 'u' && cur[3] == 'e' && !isAlphanumeric(cur[4]) && cur[4] != '_' && (cur += 4, true))
value = true;
else
throw Error::TYPE_MISMATCH;
}

void ConfigurationParser::parseSettingsJsonIO(Settings::JsonIO &value) {
std::string str;
parseStdString(str);
switch (str.size()) {
case 3:
if (str == "ANY") {
value = NameFormat::ANY;
return;
}
break;
case 9:
if (str == "CAMELCASE") {
value = NameFormat::CAMELCASE;
return;
}
break;
case 13:
if (str == "UPERCASE_DASH") {
value = NameFormat::UPERCASE_DASH;
return;
}
break;
case 14:
if (str == "LOWERCASE_DASH") {
value = NameFormat::LOWERCASE_DASH;
return;
}
break;
case 17:
if (str == "CAMELCASE_CAPITAL") {
value = NameFormat::CAMELCASE_CAPITAL;
return;
}
break;
case 20:
switch (str[0]) {
case 'L':
if (str == "LOWERCASE_UNDERSCORE") {
value = NameFormat::LOWERCASE_UNDERSCORE;
return;
}
break;
case 'U':
if (str == "UPPERCASE_UNDERSCORE") {
value = NameFormat::UPPERCASE_UNDERSCORE;
return;
}
break;
}
break;
if (str == "NULL_TERMINATED_STRING") {
value = Settings::JsonIO::NULL_TERMINATED_STRING;
return;
}
throw Error::UNKNOWN_ENUM_VALUE;
}
Expand Down Expand Up @@ -480,26 +446,6 @@ void ConfigurationParser::parseSettingsNanPolicy(Settings::NanPolicy &value) {
throw Error::UNKNOWN_ENUM_VALUE;
}

void ConfigurationParser::parseBool(bool &value) {
skipWhitespace();
if (cur[0] == 'f' && cur[1] == 'a' && cur[2] == 'l' && cur[3] == 's' && cur[4] == 'e' && !isAlphanumeric(cur[5]) && cur[5] != '_' && (cur += 5, true))
value = false;
else if (cur[0] == 't' && cur[1] == 'r' && cur[2] == 'u' && cur[3] == 'e' && !isAlphanumeric(cur[4]) && cur[4] != '_' && (cur += 4, true))
value = true;
else
throw Error::TYPE_MISMATCH;
}

void ConfigurationParser::parseSettingsJsonIO(Settings::JsonIO &value) {
std::string str;
parseStdString(str);
if (str == "NULL_TERMINATED_STRING") {
value = Settings::JsonIO::NULL_TERMINATED_STRING;
return;
}
throw Error::UNKNOWN_ENUM_VALUE;
}

void ConfigurationParser::parseSettings(Settings &value) {
std::string key;
if (!matchSymbol('{'))
Expand All @@ -511,97 +457,79 @@ void ConfigurationParser::parseSettings(Settings &value) {
parseStdString(key);
if (!matchSymbol(':'))
throw Error::JSON_SYNTAX_ERROR;
if (key.size() > 3) {
switch (key[3]) {
case 'F':
if (key == "keyFormat") {
parseNameFormat(value.keyFormat);
if (key.size() > 5) {
switch (key[5]) {
case 'I':
if (key == "checkIntegerOverflow") {
parseBool(value.checkIntegerOverflow);
continue;
}
break;
case 'P':
switch (key[0]) {
case 'i':
if (key == "infPolicy") {
parseSettingsInfPolicy(value.infPolicy);
continue;
}
break;
case 'n':
if (key == "nanPolicy") {
parseSettingsNanPolicy(value.nanPolicy);
continue;
}
break;
case 'M':
if (key == "checkMissingKeys") {
parseBool(value.checkMissingKeys);
continue;
}
break;
case 'a':
if (key == "escapeForwardSlash") {
parseBool(value.escapeForwardSlash);
case 'O':
if (key == "jsonIOMode") {
parseSettingsJsonIO(value.jsonIOMode);
continue;
}
break;
case 'b':
if (key == "verboseErrors") {
parseBool(value.verboseErrors);
case 'R':
if (key == "checkRepeatingKeys") {
parseBool(value.checkRepeatingKeys);
continue;
}
break;
case 'c':
case 'e':
switch (key.size()) {
case 16:
if (key == "checkMissingKeys") {
parseBool(value.checkMissingKeys);
case 15:
if (key == "ignoreExtraKeys") {
parseBool(value.ignoreExtraKeys);
continue;
}
break;
case 18:
if (key == "checkRepeatingKeys") {
parseBool(value.checkRepeatingKeys);
if (key == "escapeForwardSlash") {
parseBool(value.escapeForwardSlash);
continue;
}
break;
case 20:
if (key == "checkIntegerOverflow") {
parseBool(value.checkIntegerOverflow);
}
break;
case 'l':
switch (key[0]) {
case 'i':
if (key == "infPolicy") {
parseSettingsInfPolicy(value.infPolicy);
continue;
}
break;
case 'n':
if (key == "nanPolicy") {
parseSettingsNanPolicy(value.nanPolicy);
continue;
}
break;
}
break;
case 'h':
if (key == "noThrow") {
parseBool(value.noThrow);
continue;
}
break;
case 'i':
if (key == "strictSyntaxCheck") {
parseBool(value.strictSyntaxCheck);
continue;
}
break;
case 'm':
if (key == "enumFormat") {
parseNameFormat(value.enumFormat);
continue;
}
break;
case 'n':
if (key == "jsonIOMode") {
parseSettingsJsonIO(value.jsonIOMode);
if (key == "skipEmptyFields") {
parseBool(value.skipEmptyFields);
continue;
}
break;
case 'o':
if (key == "ignoreExtraKeys") {
parseBool(value.ignoreExtraKeys);
if (key == "noThrow") {
parseBool(value.noThrow);
continue;
}
break;
case 'p':
if (key == "skipEmptyFields") {
parseBool(value.skipEmptyFields);
case 't':
if (key == "strictSyntaxCheck") {
parseBool(value.strictSyntaxCheck);
continue;
}
break;
Expand Down
5 changes: 2 additions & 3 deletions generated/ConfigurationParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ class ConfigurationParser {
void parseStdVectorStdString(std::vector<std::string> &value);
void parseConfigurationGeneratorDef(Configuration::GeneratorDef &value);
void parseStdVectorConfigurationGeneratorDef(std::vector<Configuration::GeneratorDef> &value);
void parseNameFormat(NameFormat &value);
void parseSettingsInfPolicy(Settings::InfPolicy &value);
void parseSettingsNanPolicy(Settings::NanPolicy &value);
void parseBool(bool &value);
void parseSettingsJsonIO(Settings::JsonIO &value);
void parseSettingsInfPolicy(Settings::InfPolicy &value);
void parseSettingsNanPolicy(Settings::NanPolicy &value);
void parseSettings(Settings &value);
void parseStringAPI(StringAPI &value);
void parseConfigurationStringDef(Configuration::StringDef &value);
Expand Down
11 changes: 2 additions & 9 deletions src/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@

#include <string>
#include <vector>
#include "NameFormat.h"

struct Settings {
/// Specifies how the JSON data is received / outputted.
enum class JsonIO {
NULL_TERMINATED_STRING
// Stream mode will be added in the future
} jsonIOMode = JsonIO::NULL_TERMINATED_STRING;
/// Specifies how keys of structure member variables are formatted in the JSON file.
NameFormat keyFormat = NameFormat::ANY;
/// Specifies how enum values are formatted in the JSON file.
NameFormat enumFormat = NameFormat::ANY;
/// Parser / serialization errors can be thrown or returned. The latter should only be used for strictly no-throw codebases.
bool noThrow = false;
/// By default, errors are enumerated error codes. In verbose mode, they are instead a structure with the code and a message string.
bool verboseErrors = false; // TODO IMPLEMENT
/// By default, not all of the JSON's syntax is checked to save performance. Enable strict syntax checking if you want to make sure that any invalid JSON file is detected.
bool strictSyntaxCheck = false;
/// If this is enabled, any time a JSON object is parsed into a C++ structure, but not all of its fields are present in the JSON, an error will be reported.
bool checkMissingKeys = true; // TODO IMPLEMENT
bool checkMissingKeys = false; // TODO IMPLEMENT
/// Unless repeating keys are checked, repeated instances of the same key will simply result in the field being overwritten.
bool checkRepeatingKeys = true; // TODO IMPLEMENT
bool checkRepeatingKeys = false; // TODO IMPLEMENT
/// When a JSON object contains an unknown element, it can either be ignored and its value silently skipped, or an error can be reported.
bool ignoreExtraKeys = true;
/// Unless enabled, parsing integers that are too large to fit the intended variable will simply truncate them.
Expand Down
2 changes: 2 additions & 0 deletions src/Generator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "Generator.h"

#include "NameFormat.h"

const char *const Generator::signature =
"// Generated by json-cpp-gen by Viktor Chlumsky\n"
"// https://github.com/Chlumsky/json-cpp-gen\n\n";
Expand Down

0 comments on commit c389677

Please sign in to comment.