]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Fix subend function.
authorBruno Haible <bruno@clisp.org>
Sat, 9 Sep 2017 10:01:28 +0000 (12:01 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 9 Sep 2017 14:41:59 +0000 (16:41 +0200)
Make subend('a','b','Laura') return 'Laurb' instead of 'bL'.

pygnulib/constants.py

index 9e0f19460a25a28f9ff9cecfdab6de2850b7e4b4..9428e1fce6f0311d4a753a5d6682f13663e007d9 100644 (file)
@@ -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)