]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport gvanrossum's patch:
authorAnthony Baxter <anthonybaxter@gmail.com>
Thu, 18 Apr 2002 05:18:56 +0000 (05:18 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Thu, 18 Apr 2002 05:18:56 +0000 (05:18 +0000)
Partially implement SF feature request 444708.

Add optional arg to string methods strip(), lstrip(), rstrip().
The optional arg specifies characters to delete.

Also for UserString.

Still to do:

- Misc/NEWS
- LaTeX docs (I did the docstrings though)
- Unicode methods, and Unicode support in the string methods.

Original patches were:
python/dist/src/Lib/test/string_tests.py:1.12

Lib/test/string_tests.py

index e207566e6bb403c0af6aab07185e74d816f381d2..3a302c6670cafe20b553087c184e913ed5616c1c 100644 (file)
@@ -163,6 +163,18 @@ def run_method_tests(test):
     test('rstrip', '   hello   ', '   hello')
     test('strip', 'hello', 'hello')
 
+    # strip/lstrip/rstrip with None arg
+    test('strip', '   hello   ', 'hello', None)
+    test('lstrip', '   hello   ', 'hello   ', None)
+    test('rstrip', '   hello   ', '   hello', None)
+    test('strip', 'hello', 'hello', None)
+
+    # strip/lstrip/rstrip with real arg
+    test('strip', 'xyzzyhelloxyzzy', 'hello', 'xyz')
+    test('lstrip', 'xyzzyhelloxyzzy', 'helloxyzzy', 'xyz')
+    test('rstrip', 'xyzzyhelloxyzzy', 'xyzzyhello', 'xyz')
+    test('strip', 'hello', 'hello', 'xyz')
+
     test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
     test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')