aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QUtil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-11-09 17:54:16 +0100
committerJay Berkenbilt <ejb@ql.org>2019-11-09 19:23:12 +0100
commitc4478e5249f935abe852b11275ffe48c29d8f997 (patch)
treee797874704e755a99eb170c2d6fe0b0ace03df52 /libqpdf/QUtil.cc
parentc9cc83621bf383a135699e2c952713eb592ebcb7 (diff)
downloadqpdf-c4478e5249f935abe852b11275ffe48c29d8f997.tar.zst
Allow odd/even modifiers in numeric range (fixes #364)
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r--libqpdf/QUtil.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index db52bdb3..5fda01c9 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -1116,6 +1116,8 @@ QUtil::parse_numrange(char const* range, int max)
std::vector<int> work;
static int const comma = -1;
static int const dash = -2;
+ size_t start_idx = 0;
+ size_t skip = 1;
enum { st_top,
st_in_number,
@@ -1182,6 +1184,14 @@ QUtil::parse_numrange(char const* range, int max)
work.push_back(dash);
}
}
+ else if (ch == ':')
+ {
+ if (! ((state == st_in_number) || (state == st_after_number)))
+ {
+ throw std::runtime_error("unexpected colon");
+ }
+ break;
+ }
else
{
throw std::runtime_error("unexpected character");
@@ -1197,6 +1207,22 @@ QUtil::parse_numrange(char const* range, int max)
{
throw std::runtime_error("number expected");
}
+ if (*p == ':')
+ {
+ if (strcmp(p, ":odd") == 0)
+ {
+ skip = 2;
+ }
+ else if (strcmp(p, ":even") == 0)
+ {
+ skip = 2;
+ start_idx = 1;
+ }
+ else
+ {
+ throw std::runtime_error("unexpected even/odd modifier");
+ }
+ }
p = 0;
for (size_t i = 0; i < work.size(); i += 2)
@@ -1245,6 +1271,15 @@ QUtil::parse_numrange(char const* range, int max)
}
}
}
+ if ((start_idx > 0) || (skip != 1))
+ {
+ auto t = result;
+ result.clear();
+ for (size_t i = start_idx; i < t.size(); i += skip)
+ {
+ result.push_back(t.at(i));
+ }
+ }
}
catch (std::runtime_error const& e)
{