RGXG_NUMBER_RANGE(3) | librgxg manual | RGXG_NUMBER_RANGE(3) |
rgxg_number_range, rgxg_number_greaterequal - create regex that matches integers in the given range
#include <rgxg/number.h> int rgxg_number_range (long long first, long long last, int base, size_t min_length, char *regex, rgxg_options_t options); int rgxg_number_greaterequal (long long number, int base, size_t min_length, char *regex, rgxg_options_t options);
rgxg_number_range() generates the (extended) regular expression that matches integers in the range between first and last.
rgxg_number_greaterequal() generates the (extended) regular expression that matches integers greater than or equal to number.
The base of the matched integers is specified by base, which must be between 2 and 32 inclusive. Note that for bases greater than 16 the "extended hex" alphabet is used (referenced as 'base32hex' in RFC 4648).
If RGXG_LEADINGZERO or RGXG_VARLEADINGZERO is set, then min_length specifies the minimum length of the matched integers (otherwise the argument is ignored). For instance the number 5 with min_length set to 3 and options set to RGXG_LEADINGZERO is matched as '005'. By default the number of leading zeros depends on the length of the last number. If min_length is lesser than or equal to the number of digits of last, the value has no effect.
The generated regular expression is written to the character string regex, including the terminating null byte ('\0'), unless RGXG_NONULLBYTE is set. If regex is NULL the return value is the number of characters (excluding the terminating null byte) that would have been written in case regex has been initialized. Note that the functions assume an arbitrarily long regex string, callers must ensure that the given string is large enough to not overflow the actual space.
options is either zero, or the bitwise-or of one or more of the following macros:
Note that RGXG_NOUPPERCASE and RGXG_NOLOWERCASE as well as RGXG_LEADINGZERO and RGXG_VARLEADINGZERO are mutual exclusive options.
Upon successful return, these functions return the number of characters (excluding the terminating null byte) written to regex.
If an error occurs, a (negative) error code is returned (see ERRORS section).
The following errors can be returned:
These functions are available since rgxg 0.1.
regex(7), rgxg_net_cidr_ipv4(3), rgxg_net_cidr_ipv6(3), rgxg_net_cidr_string(3).
Hannes von Haugwitz <hannes@vonhaugwitz.com>
April 12, 2020 | rgxg 0.1.2 |