RGXG_UTILS_ESCAPE_STRING(3)

πŸ’– RGXG_UTILS_ESCAPE_STRING πŸ’–

okay bestie, sit down, hydrate, and let me tell you about rgxg_utils_escape_string from the librgxg manual (section 3, we're fancy like that). this one's a lil function that makes strings safe for regex land, and it's genuinely so useful. no cap. πŸ¦‹


✨ NAME ✨

rgxg_utils_escape_string β€” escape the given string for use in a regular expression

like. that's it. that's the whole job. it takes a string and makes it regex-safe so none of the special characters go feral on you. πŸ’…


🌸 SYNOPSIS 🌸

#include <rgxg/utils.h>

int rgxg_utils_escape_string (const char *src, size_t size,
     char *regex, rgxg_options_t options);

πŸ’œ DESCRIPTION πŸ’œ

so here's the tea, bestie. rgxg_utils_escape_string() generates the (extended) regular expression that matches at most size bytes of the given string src β€” or up to the first null byte, whichever comes first β€” and it does that by escaping the regular expression special characters. basically it takes your chaotic little string and gives it a glow-up so it behaves in a regex. πŸŽ€

lowkey important: src must be valid and not NULL. do not test this. it will not pass the vibe check.

the generated regular expression gets written to the character string regex, and yes it includes the terminating null byte ('\0') β€” UNLESS RGXG_NONULLBYTE is set, in which case it does not. iconique behavior. πŸ™ˆ

now, 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 had been initialized. it's giving "just tell me how much space i need, bestie." πŸ’–

⚠️ heads up: these functions assume an arbitrarily long regex string. callers must ensure that the given string is large enough to not overflow the actual space. that's on you, not on the function. no safety net, fr fr.

options is either zero, or set to the following macro:

  • RGXG_NONULLBYTE β€” Do not add the terminating null byte ('\0') to the regex string.

πŸ‘‘ RETURN VALUE πŸ‘‘

rgxg_utils_escape_string() returns the number of characters (excluding the terminating null byte) written to regex. so like, a count. a lil number. your receipt. 🧾✨


🌈 AVAILABILITY 🌈

This function is available since rgxg 0.1. she's been here. she's a legend. periodt. πŸ’…


πŸ”₯ SEE ALSO πŸ”₯


🫢 AUTHOR 🫢

Hannes von Haugwitz <hannes@vonhaugwitz.com>


and that's the whole page, bestie!! this lil beauty shipped in rgxg 0.1.2, dated Apr 12, 2020 β€” go forth and escape responsibly, mwah πŸ’–βœ¨πŸŽ€πŸ¦‹