RGXG_NUMBER_RANGE(3)

πŸ’– RGXG_NUMBER_RANGE πŸ’–

okay bestie, so you know how librgxg has this whole thing β€” and this page is from the librgxg manual? yeah. we're talking about rgxg_number_range and rgxg_number_greaterequal today and honestly? they ate. let's go 🫢


✨ NAME ✨

so basically there's two of them, and they're besties:

  • rgxg_number_range, rgxg_number_greaterequal β€” they build you a regex that matches integers in the given range. that's the whole job. that's the vibe. πŸ’…

🌸 SYNOPSIS 🌸

like, here's the tea, literally copy this:

#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);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so first up, rgxg_number_range() β€” it generates the (extended) regular expression that matches integers in the range between first and last. cute, right? no cap.

then rgxg_number_greaterequal() generates the (extended) regular expression that matches integers greater than or equal to number. so like, "this and everything above it". iconic behaviour honestly.

the base of the matched integers is specified by base, and it must be between 2 and 32 inclusive β€” that's the law, bestie, don't test it. ⚠️ also heads up: for bases greater than 16 the "extended hex" alphabet gets used (it's referenced as 'base32hex' in RFC 4648, iykyk).

now, if RGXG_LEADINGZERO or RGXG_VARLEADINGZERO is set, then min_length specifies the minimum length of the matched integers β€” otherwise that argument just gets ignored entirely, like it's not even there. for instance the number 5 with min_length set to 3 and options set to RGXG_LEADINGZERO is matched as '005'. slay. by default the number of leading zeros depends on the length of the last number. and if min_length is lesser than or equal to the number of digits of last, the value has no effect. yeah. nothing. zero. πŸ’€

the generated regular expression gets written to the character string regex, including the terminating null byte ('\0') β€” unless RGXG_NONULLBYTE is set. and if regex is NULL? then the return value is the number of characters (excluding the terminating null byte) that would have been written in case regex has been initialized. πŸ‘‘

⚠️ real talk: note that the functions assume an arbitrarily long regex string, so callers must ensure that the given string is large enough to not overflow the actual space. do not play with this one bestie, fr fr.

options is either zero, or the bitwise-or of one or more of the following macros:


πŸ’… OPTIONS πŸ’…

  • RGXG_NOUPPERCASE β€” the generated regular expression only matches lower case letters for base values greater than 10. the default is to match both lower and upper case letters.
  • RGXG_NOLOWERCASE β€” the generated regular expression only matches upper case letters for base values greater than 10. the default is to match both lower and upper case letters.
  • RGXG_NOOUTERPARENS β€” omit the outer parenthesis, if any, of the regular expression. bye bye parens πŸŽ€
  • RGXG_LEADINGZERO β€” the generated regular expression only matches integers with leading zeros (e.g. the integer 5 is only matched as '005'). the number of leading zeros is influenced by the min_length argument (see above). by default no leading zeros are matched.
  • RGXG_VARLEADINGZERO β€” the generated regular expression matches integers with a variable number of leading zeros (e.g. the number 5 is matched as '5', '05' and '005'). the maximum number of leading zeros is influenced by the min_length argument (see above). by default no leading zeros are matched.
  • RGXG_NONULLBYTE β€” do not add the terminating null byte ('\0') to the regex string.
🚨 note that RGXG_NOUPPERCASE and RGXG_NOLOWERCASE as well as RGXG_LEADINGZERO and RGXG_VARLEADINGZERO are mutual exclusive options. pick a lane bestie, you cannot have both. πŸ™ˆ

⭐ RETURN VALUE ⭐

upon successful return, these functions return the number of characters (excluding the terminating null byte) written to regex. periodt.

if an error occurs, a (negative) error code is returned (see ERRORS section). yeah, negative. sad girl hours. 😭


🌈 ERRORS 🌈

the following errors can be returned:

  • RGXG_ERROR_RANGE (rgxg_number_range() only) β€” invalid range (e.g. first number is greater than last number). make it make sense, bestie.
  • RGXG_ERROR_BASE β€” the base is lesser than 2 or greater than 32.
  • RGXG_ERROR_NEGARG β€” at least one argument is negative.
  • RGXG_ERROR_ARG2BIG (rgxg_number_greaterequal() only) β€” the value of number is too large.
  • RGXG_ERROR_MUTEXOPTIONS β€” two mutual exclusive options were specified. told you. πŸ™ˆ

🧚 AVAILABILITY 🧚

these functions are available since rgxg 0.1. vintage. retro. still serving. ✨


πŸ”₯ SEE ALSO πŸ”₯

regex(7), rgxg_net_cidr_ipv4(3), rgxg_net_cidr_ipv6(3), rgxg_net_cidr_string(3).

go read those too, they're part of the same friend group πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Hannes von Haugwitz <hannes@vonhaugwitz.com>


and that's the whole page babes πŸŽ€ this was the librgxg manual, page RGXG_NUMBER_RANGE(3), from rgxg 0.1.2, dated Apr 12, 2020. mwah, go write some regexes, you're gonna do amazing πŸ¦‹πŸ’–