From 342f702aa4bdd014cdb6537280e4c4ef72ded4f6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 18 Jan 2009 04:07:35 +0100 Subject: [PATCH] Improve func_remove_prefix, func_remove_suffix. --- ChangeLog | 9 +++++++++ gnulib-tool | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d126c3b39..f779accbb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2009-01-17 Bruno Haible + * gnulib-tool (func_remove_prefix): Escape all dots in the prefix. + Update documentation. + (func_remove_suffix): Escape all dots in the suffix. Update + documentation. + (func_filter_filelist): Update documentation. + Reported by Ralf Wildenhues. + +2009-01-17 Bruno Haible + * modules/dprintf-posix-tests: New file. * tests/test-dprintf-posix.sh: New file. * tests/test-dprintf-posix.c: New file. diff --git a/gnulib-tool b/gnulib-tool index 965f5169d..c11ef354d 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -411,7 +411,7 @@ fi # 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 "$`\{}|. +# prefix should not contain the characters "$`\{}[]^|. if ( foo=bar; eval 'test "${foo#b}" = ar' ) >/dev/null 2>&1; then func_remove_prefix () { @@ -423,6 +423,12 @@ else { eval "value=\"\$$1\"" prefix="$2" + case "$prefix" in + *.*) + sed_escape_dots='s/\([.]\)/\\\1/g' + prefix=`echo "$prefix" | sed -e "$sed_escape_dots"` + ;; + esac value=`echo "$value" | sed -e "s|^${prefix}||"` eval "$1=\"\$value\"" } @@ -433,7 +439,7 @@ fi # removes the given suffix 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. -# suffix should not contain the characters "$`\{}|. +# suffix should not contain the characters "$`\{}[]^|. if ( foo=bar; eval 'test "${foo%r}" = ba' ) >/dev/null 2>&1; then func_remove_suffix () { @@ -445,6 +451,12 @@ else { eval "value=\"\$$1\"" suffix="$2" + case "$suffix" in + *.*) + sed_escape_dots='s/\([.]\)/\\\1/g' + suffix=`echo "$suffix" | sed -e "$sed_escape_dots"` + ;; + esac value=`echo "$value" | sed -e "s|${suffix}\$||"` eval "$1=\"\$value\"" } @@ -1379,7 +1391,7 @@ func_get_filelist () # elements starting with prefix and ending with suffix are considered. # Processing: removed_prefix and removed_suffix are removed from each element, # added_prefix and added_suffix are added to each element. -# removed_prefix, removed_suffix should not contain the characters "$`\{}|. +# removed_prefix, removed_suffix should not contain the characters "$`\{}[]^|. # added_prefix, added_suffix should not contain the characters \|. func_filter_filelist () { -- 2.11.0