* Bruno Haible wrote on Fri, Jan 02, 2009 at 02:26:52AM CET: > > * gnulib-tool (func_strip): New function. > > You only ever need to strip the prefix _or_ the suffix, never both > simultaneously. Therefore it will be faster to define 2 functions.
If it is ever possible that both are needed at the same time, then it will be beneficial to have one function to do both. If not, then it will not hurt in practice: Two mallocs and short string copies in the fast case are negligible compared with the chance of one extra fork per invocation in the slow case. > > +# func_strip name prefix suffix > > This function is insufficiently documented: What restrictions apply to > 'name', 'prefix', 'suffix'? Agreed. I would have redone the patch, too. > +# func_remove_prefix var prefix > +# removes the given prefix from the value of the shell variable var. > +# var should be the name of a shell variable. > +# Its value should not contain a newline and not start or end with > whitespace. > +# prefix should not contain the characters "$`\{}|. Not sure whether this comment is meant to list the dot as one of the forbidden characters, but neither prefix nor suffix should contain a dot in the general case, because the sed script will match any character at that position. Sorry for introducing this bug in my version of the patch when carrying over from Libtool: the Libtool version has a special case for allowing a leading dot in the suffix. Here it is for reference: # func_stripname prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). # func_strip_suffix prefix name func_stripname () { case ${2} in .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%\\\\${2}\$%%"`;; *) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;; esac } Of course, your documentation should also list the characters [ ] ^ as forbidden (both prefix and suffix). Likewise for func_filter_filelist. Cheers, Ralf