aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFJob_json.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-01 00:15:10 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-01 00:16:09 +0100
commit21b9290785fb03477784cf6312f57cfb96dbe53d (patch)
treeba51fcff3ed2982623d4ce9cd88c490eee34f95d /libqpdf/QPDFJob_json.cc
parentea96330bb615791de58a4f6beb6203137fe1ba35 (diff)
downloadqpdf-21b9290785fb03477784cf6312f57cfb96dbe53d.tar.zst
QPDFJob json: make bare arguments expect the empty string
Changing from bool requiring true to string requiring the empty string is more consistent with the CLI and makes it possible to add an optional parameter or choices later without breaking compatibility.
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)