]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Makefile uses $> more often; cgen supports filename argument; added
authorGuido van Rossum <guido@python.org>
Fri, 11 Sep 1992 23:55:51 +0000 (23:55 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 11 Sep 1992 23:55:51 +0000 (23:55 +0000)
lower, upper and swapcase to strop; cosmetics.

Modules/cgen.py
Modules/stropmodule.c

index d6e9c9646fa99e29f0e5baad784a6e5dc70bc549..ea4626365d6265009455206fd7e5991118750261 100644 (file)
@@ -376,6 +376,11 @@ def mkobject(type, arg):
        return 'mknew' + type + 'object(' + arg + ')'
 
 
+# Open optional file argument
+if sys.argv[1:]:
+       sys.stdin = open(sys.argv[1], 'r')
+
+
 # Input line number
 lno = 0
 
index cc2e26a5a995f092b1ff8327226b0c28520d4e08..835c7dbfce04ffbe8bfe7ec7050cc24895f18da3 100644 (file)
@@ -181,13 +181,121 @@ strop_strip(self, args)
 }
 
 
+#include <ctype.h>
+
+static object *
+strop_lower(self, args)
+       object *self; /* Not used */
+       object *args;
+{
+       char *s;
+       int i, n;
+       object *new;
+       int changed;
+
+       if (!getargs(args, "s#", &s, &n))
+               return NULL;
+       new = newsizedstringobject(s, n);
+       if (new == NULL)
+               return NULL;
+       s = getstringvalue(new);
+       changed = 0;
+       for (i = 0; i < n; i++) {
+               char c = s[i];
+               if (isupper(c)) {
+                       changed = 1;
+                       s[i] = tolower(c);
+               }
+       }
+       if (!changed) {
+               DECREF(new);
+               INCREF(args);
+               return args;
+       }
+       return new;
+}
+
+
+static object *
+strop_upper(self, args)
+       object *self; /* Not used */
+       object *args;
+{
+       char *s;
+       int i, n;
+       object *new;
+       int changed;
+
+       if (!getargs(args, "s#", &s, &n))
+               return NULL;
+       new = newsizedstringobject(s, n);
+       if (new == NULL)
+               return NULL;
+       s = getstringvalue(new);
+       changed = 0;
+       for (i = 0; i < n; i++) {
+               char c = s[i];
+               if (islower(c)) {
+                       changed = 1;
+                       s[i] = toupper(c);
+               }
+       }
+       if (!changed) {
+               DECREF(new);
+               INCREF(args);
+               return args;
+       }
+       return new;
+}
+
+
+static object *
+strop_swapcase(self, args)
+       object *self; /* Not used */
+       object *args;
+{
+       char *s;
+       int i, n;
+       object *new;
+       int changed;
+
+       if (!getargs(args, "s#", &s, &n))
+               return NULL;
+       new = newsizedstringobject(s, n);
+       if (new == NULL)
+               return NULL;
+       s = getstringvalue(new);
+       changed = 0;
+       for (i = 0; i < n; i++) {
+               char c = s[i];
+               if (islower(c)) {
+                       changed = 1;
+                       s[i] = toupper(c);
+               }
+               else if (isupper(c)) {
+                       changed = 1;
+                       s[i] = tolower(c);
+               }
+       }
+       if (!changed) {
+               DECREF(new);
+               INCREF(args);
+               return args;
+       }
+       return new;
+}
+
+
 /* List of functions defined in the module */
 
 static struct methodlist strop_methods[] = {
        {"index",       strop_index},
+       {"lower",       strop_lower},
        {"split",       strop_split},
        {"splitfields", strop_splitfields},
        {"strip",       strop_strip},
+       {"swapcase",    strop_swapcase},
+       {"upper",       strop_upper},
        {NULL,          NULL}   /* sentinel */
 };