On 09/20/2010 10:21 AM, Bruno Haible wrote:
Hi Eric,
/* regex_quote converts a literal string to a regular expression that will
look for this literal string.
cflags can be 0 or REG_EXTENDED.
If it is 0, the result is a Basic Regular Expression (BRE)
<http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03>.
If it is REG_EXTENDED, the result is an Extended Regular Expression (ERE)
<http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04>.
The result is not anchored; if you want it to match only complete lines,
you need to add "^" at the beginning of the result and "$" at the end of
the
result.
Since we're already passing a flag, can we add another flag that adds
the ^ and $ anchors? It's more convenient to do just one malloc (via
the regex_quote) that also adds the anchors, than it is to have to
manually call regex_quote_length, increment the result, malloc the
space, insert the anchors, then call regex_quote_copy.
It's an interesting suggestion. But frankly, the benefit of such an option is
small: It's straightforward, even in C, to prepend a "^" and append a "$" to
a string. In the way you describe, or through
regex = xasprintf ("^%s$", regex);
And adding this flag would mean that the cflags of regex_quote no longer are
a subset of the flags passed to regcomp.
So, for the moment (until there's more heavy demand for such a flag), I prefer
to address this issue only through the comments above.
Or, rather than adding a new flag big, what about providing
regex_quote_anchored as a wrapper that provides the anchors, so that the
end user can choose between the one-liners of regex_quote or
regex_quote_anchored?
--
Eric Blake ebl...@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org