From: Bruno Haible Date: Sat, 9 Sep 2017 10:01:28 +0000 (+0200) Subject: gnulib-tool.py: Fix subend function. X-Git-Tag: v1.0~5931 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=5aa8b0d419518889a8d6f392c2d38fdd438ce39f;p=gnulib.git gnulib-tool.py: Fix subend function. Make subend('a','b','Laura') return 'Laurb' instead of 'bL'. --- diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 9e0f19460a..9428e1fce6 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -397,6 +397,10 @@ def filter_filelist(separator, filelist, def substart(orig, repl, data): + '''Replaces the start portion of a string. + + Returns data with orig replaced by repl, but only at the beginning of data. + Like data.replace(orig,repl), except only at the beginning of data.''' result = data if data.startswith(orig): result = repl + data[len(orig):] @@ -404,9 +408,13 @@ def substart(orig, repl, data): def subend(orig, repl, data): + '''Replaces the end portion of a string. + + Returns data with orig replaced by repl, but only at the end of data. + Like data.replace(orig,repl), except only at the end of data.''' result = data if data.endswith(orig): - result = repl + data[:len(repl)] + result = data[:-len(orig)] + repl return(result)