summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2001-01-29 11:14:16 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2001-01-29 11:14:16 (GMT)
commitfde66e1bcc4431a59f36bad0ca0dd7a848ce794b (patch)
tree6f8050abb89c2c8ad8cec8c24b06b31ee037221d /Objects
parent30be8708c544f1b6a0ebacf856915830c6b36d39 (diff)
downloadcpython-fde66e1bcc4431a59f36bad0ca0dd7a848ce794b.zip
cpython-fde66e1bcc4431a59f36bad0ca0dd7a848ce794b.tar.gz
cpython-fde66e1bcc4431a59f36bad0ca0dd7a848ce794b.tar.bz2
Fixed .capitalize() method of Unicode objects to work like the
corresponding string method. Added tests for this too. Patch written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 5c193dd..7b12594 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -2631,11 +2631,25 @@ int fixswapcase(PyUnicodeObject *self)
static
int fixcapitalize(PyUnicodeObject *self)
{
- if (self->length > 0 && Py_UNICODE_ISLOWER(self->str[0])) {
- self->str[0] = Py_UNICODE_TOUPPER(self->str[0]);
- return 1;
+ int len = self->length;
+ Py_UNICODE *s = self->str;
+ int status = 0;
+
+ if (len == 0)
+ return 0;
+ if (Py_UNICODE_ISLOWER(*s)) {
+ *s = Py_UNICODE_TOUPPER(*s);
+ status = 1;
}
- return 0;
+ s++;
+ while (--len > 0) {
+ if (Py_UNICODE_ISUPPER(*s)) {
+ *s = Py_UNICODE_TOLOWER(*s);
+ status = 1;
+ }
+ s++;
+ }
+ return status;
}
static