Subject: Re: search.c clean-up
On Nov 23, 2004, at 12:48, Jim Meyering wrote:
Elliott Hughes <enh@xxxxxxxxxxx> wrote:
i like this partial factorization -- even though there's more stuff to
also come out -- because it's a meaningful chunk of functionality in
its own right, and deserves a name.
i'd rather see a function than a multi-line macro, though.
I prefer functions too, in general but I don't particularly like
the 6-parameter interface (and even less the 4-param one including
two in/out parameters -- it's bad enough that I've done that in
the macro). What did you have in mind?
The problem with the 4-parameter approach
wrap_pattern (char *pattern, size_t *pattern_len,
char const *prefix, char const *suffix)
is that it works fine when we don't have to free the PATTERN,
but if anyone ever calls it with a malloc'd PATTERN, it will leak.
return char*, and -- at the risk of more nitpickery -- expect the user
to call strlen if they need to know how long the pattern is?
"static char* wrap_pattern(const char* pattern, const char* prefix,
const char* suffix)" seems reasonable to me.
or rename search.c as search.cpp and use std::string. all this
pretending a char* is a string is *so* 1970s. (see also the comment
starting "The PCRE interface doesn't allow NUL bytes in the pattern..."
in the same file.)