summaryrefslogtreecommitdiff
path: root/Modules/stropmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-06-12 04:24:52 +0000
committerGuido van Rossum <guido@python.org>1996-06-12 04:24:52 +0000
commita7b52ec626b90b15d7083fc186f452c344ca06fa (patch)
treecc52101cb339557435a04c6bf96ba3abde96632d /Modules/stropmodule.c
parenteca0d1032a7cce2567280d93e8252b672342f5c6 (diff)
downloadcpython-a7b52ec626b90b15d7083fc186f452c344ca06fa.tar.gz
added capitalize()
Diffstat (limited to 'Modules/stropmodule.c')
-rw-r--r--Modules/stropmodule.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c
index a82c3138ed..52d4cee366 100644
--- a/Modules/stropmodule.c
+++ b/Modules/stropmodule.c
@@ -368,6 +368,50 @@ strop_upper(self, args)
static object *
+strop_capitalize(self, args)
+ object *self; /* Not used */
+ object *args;
+{
+ char *s, *s_new;
+ int i, n;
+ object *new;
+ int changed;
+
+ if (!getargs(args, "s#", &s, &n))
+ return NULL;
+ new = newsizedstringobject(NULL, n);
+ if (new == NULL)
+ return NULL;
+ s_new = getstringvalue(new);
+ changed = 0;
+ {
+ int c = Py_CHARMASK(*s++);
+ if (islower(c)) {
+ changed = 1;
+ *s_new = toupper(c);
+ } else
+ *s_new = c;
+ s_new++;
+ }
+ for (i = 1; i < n; i++) {
+ int c = Py_CHARMASK(*s++);
+ if (isupper(c)) {
+ changed = 1;
+ *s_new = tolower(c);
+ } else
+ *s_new = c;
+ s_new++;
+ }
+ if (!changed) {
+ DECREF(new);
+ INCREF(args);
+ return args;
+ }
+ return new;
+}
+
+
+static object *
strop_swapcase(self, args)
object *self; /* Not used */
object *args;
@@ -538,6 +582,7 @@ static struct methodlist strop_methods[] = {
{"atof", strop_atof},
{"atoi", strop_atoi},
{"atol", strop_atol},
+ {"capitalize", strop_capitalize},
{"find", strop_find},
{"join", strop_joinfields, 1},
{"joinfields", strop_joinfields, 1},