GNOME Bugzilla – Bug 615895
[PATCH] (indirectly) support non-NULL-terminated regexes in GRegex
Last modified: 2011-08-23 20:37:49 UTC
GRegex has no interface to match strings that are not NULL-terminated. This patch adds an escaping function that can be used to this end, without redesigning the way the pattern is stored in GRegex objects and retrieved with g_regex_get_pattern. As an alternative, this code could be used in a function that directly wraps g_regex_new. That would be fine for me too, please review. Testcases included.
Created attachment 158849 [details] [review] patch
Created attachment 158857 [details] [review] addendum
Note that your bug title is misleading, because it still doesn't support non-nul-terminated strings with your patch. I like the patch though.
ping?
Created attachment 179398 [details] [review] updated patch
Looks fine to me in principle. Looking at g_regex_escape_string for comparison, it lacks the backslash counting you have here - which looks like a bug...
Review of attachment 179398 [details] [review]: Please commit
The following fix has been pushed: 5eee90f add g_regex_escape_nul
Created attachment 191673 [details] [review] add g_regex_escape_nul The function can be used to let regex compile non-NUL-terminated strings without redesigning the way the pattern is stored in GRegex objects and retrieved with g_regex_get_pattern.
The backslash counting is only needed here because a string that is a backslash and a NUL must be escaped to "\\x00" (the backslash was uselessly escaping the NUL), while a string that is *two* backslashes and a NUL must be escaped to "\\\\\\x00" (the backslashes were their own escape, and a third must be added as part of escaping the NUL). Confusing, yes...