summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2006-05-26 18:24:15 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2006-05-26 18:24:15 (GMT)
commit9c0e9c089c758bc9b64f0379bc93f8ea6740eb53 (patch)
treefaf6ca0008b35c87a91be9a990f13955e2545502
parentb3167cbcd76652f9f5f64196ce371562bcd8d42c (diff)
downloadcpython-9c0e9c089c758bc9b64f0379bc93f8ea6740eb53.zip
cpython-9c0e9c089c758bc9b64f0379bc93f8ea6740eb53.tar.gz
cpython-9c0e9c089c758bc9b64f0379bc93f8ea6740eb53.tar.bz2
needspeed: rpartition documentation, tests, and a bug fixes.
feel free to add more tests and improve the documentation.
-rw-r--r--Doc/lib/libstdtypes.tex9
-rw-r--r--Lib/test/string_tests.py19
-rw-r--r--Objects/unicodeobject.c4
3 files changed, 28 insertions, 4 deletions
diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex
index 798585a..576a5ad 100644
--- a/Doc/lib/libstdtypes.tex
+++ b/Doc/lib/libstdtypes.tex
@@ -763,6 +763,15 @@ The original string is returned if
\versionchanged[Support for the \var{fillchar} argument]{2.4}
\end{methoddesc}
+\begin{methoddesc}[string]{rpartition}{sep}
+Split the string at the last occurrence of \var{sep}, and return
+a 3-tuple containing the part before the separator, the separator
+itself, and the part after the separator. If the separator is not
+found, return a 3-tuple containing the string itself, followed by
+two empty strings.
+\versionadded{2.5}
+\end{methoddesc}
+
\begin{methoddesc}[string]{rsplit}{\optional{sep \optional{,maxsplit}}}
Return a list of the words in the string, using \var{sep} as the
delimiter string. If \var{maxsplit} is given, at most \var{maxsplit}
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index e242170..489af20 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -999,8 +999,8 @@ class MixinStrUnicodeUserStringTest:
def test_partition(self):
- self.checkequal(('this', ' is ', 'the partition method'),
- 'this is the partition method', 'partition', ' is ')
+ self.checkequal(('this is the par', 'ti', 'tion method'),
+ 'this is the partition method', 'partition', 'ti')
# from raymond's original specification
S = 'http://www.python.org'
@@ -1012,6 +1012,21 @@ class MixinStrUnicodeUserStringTest:
self.checkraises(ValueError, S, 'partition', '')
self.checkraises(TypeError, S, 'partition', None)
+ def test_rpartition(self):
+
+ self.checkequal(('this is the rparti', 'ti', 'on method'),
+ 'this is the rpartition method', 'rpartition', 'ti')
+
+ # from raymond's original specification
+ S = 'http://www.python.org'
+ self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://')
+ self.checkequal(('http://www.python.org', '', ''), S, 'rpartition', '?')
+ self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://')
+ self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org')
+
+ self.checkraises(ValueError, S, 'rpartition', '')
+ self.checkraises(TypeError, S, 'rpartition', None)
+
class MixinStrStringUserStringTest:
# Additional tests for 8bit strings, i.e. str, UserString and
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index df15f4b..7d644d3 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3861,8 +3861,8 @@ int PyUnicode_EncodeDecimal(Py_UNICODE *s,
Py_LOCAL(int)
STRINGLIB_CMP(const Py_UNICODE* str, const Py_UNICODE* other, Py_ssize_t len)
{
- if (str[0] == other[0])
- return 0;
+ if (str[0] != other[0])
+ return 1;
return memcmp((void*) str, (void*) other, len * sizeof(Py_UNICODE));
}