aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFJob_json.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf/QPDFJob_json.cc')
-rw-r--r--libqpdf/QPDFJob_json.cc33
1 files changed, 20 insertions, 13 deletions
diff --git a/libqpdf/QPDFJob_json.cc b/libqpdf/QPDFJob_json.cc
index 3091c7b1..cc4e2ff7 100644
--- a/libqpdf/QPDFJob_json.cc
+++ b/libqpdf/QPDFJob_json.cc
@@ -31,7 +31,7 @@ namespace
void addBare(bare_handler_t);
void addParameter(param_handler_t);
- void addChoices(char const** choices, param_handler_t);
+ void addChoices(char const** choices, bool required, param_handler_t);
void pushKey(std::string const& key);
void beginDict(json_handler_t start_fn,
bare_handler_t end_fn);
@@ -106,11 +106,12 @@ Handlers::initHandlers()
void
Handlers::addBare(bare_handler_t fn)
{
- jh->addBoolHandler([this, fn](std::string const& path, bool v){
- if (! v)
+ jh->addStringHandler(
+ [this, fn](std::string const& path, std::string const& parameter){
+ if (! parameter.empty())
{
- QTC::TC("qpdf", "QPDFJob json bare not true");
- usage(path + ": value must be true");
+ QTC::TC("qpdf", "QPDFJob json bare not empty");
+ usage(path + ": value must be the empty string");
}
else
{
@@ -129,22 +130,28 @@ Handlers::addParameter(param_handler_t fn)
}
void
-Handlers::addChoices(char const** choices,
- param_handler_t fn)
+Handlers::addChoices(char const** choices, bool required, param_handler_t fn)
{
jh->addStringHandler(
- [fn, choices, this](
+ [fn, choices, required, this](
std::string const& path, std::string const& parameter){
char const* p = parameter.c_str();
bool matches = false;
- for (char const** i = choices; *i; ++i)
+ if ((! required) && (parameter.empty()))
+ {
+ matches = true;
+ }
+ if (! matches)
{
- if (strcmp(*i, p) == 0)
+ for (char const** i = choices; *i; ++i)
{
- QTC::TC("qpdf", "QPDFJob json choice match");
- matches = true;
- break;
+ if (strcmp(*i, p) == 0)
+ {
+ QTC::TC("qpdf", "QPDFJob json choice match");
+ matches = true;
+ break;
+ }
}
}
if (! matches)