diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-05-11 12:42:12 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-05-13 11:42:00 +0200 |
commit | 4ce9b5a1023be2e931d4205ed17f44f135c920d1 (patch) | |
tree | a8fdee5c427d6c0b4e907e4b902d751e69fe972f /source/fitz/string.c | |
parent | ae9780583c18c949bf975131a24eb8b8361ddbf6 (diff) | |
download | mupdf-4ce9b5a1023be2e931d4205ed17f44f135c920d1.tar.xz |
Add common page range parsing function for tools.
Diffstat (limited to 'source/fitz/string.c')
-rw-r--r-- | source/fitz/string.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/source/fitz/string.c b/source/fitz/string.c index 95b216fe..df171795 100644 --- a/source/fitz/string.c +++ b/source/fitz/string.c @@ -416,3 +416,50 @@ fz_off_t fz_atoo(const char *s) return 0; return fz_atoo_imp(s); } + +int fz_is_page_range(fz_context *ctx, const char *s) +{ + /* TODO: check the actual syntax... */ + while (*s) + { + if ((*s < '0' || *s > '9') && *s != 'N' && *s != '-' && *s != ',') + return 0; + s++; + } + return 1; +} + +const char *fz_parse_page_range(fz_context *ctx, const char *s, int *a, int *b, int n) +{ + if (!s || !s[0]) + return NULL; + + if (s[0] == ',') + s += 1; + + if (s[0] == 'N') + { + *a = n; + s += 1; + } + else + *a = strtol(s, (char**)&s, 10); + + if (s[0] == '-') + { + if (s[1] == 'N') + { + *b = n; + s += 2; + } + else + *b = strtol(s+1, (char**)&s, 10); + } + else + *b = *a; + + *a = fz_clampi(*a, 1, n); + *b = fz_clampi(*b, 1, n); + + return s; +} |