summaryrefslogtreecommitdiffstats
path: root/Modules/stropmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-09-13 17:39:06 (GMT)
committerGuido van Rossum <guido@python.org>1995-09-13 17:39:06 (GMT)
commita3127e8e1149f20e780cf703fef217ee499d5e75 (patch)
tree21f006d14f63b89d6282663275204f9408f94c78 /Modules/stropmodule.c
parent8d8c1eeed7fa7749f8247d1b5172acbb033f87ac (diff)
downloadcpython-a3127e8e1149f20e780cf703fef217ee499d5e75.zip
cpython-a3127e8e1149f20e780cf703fef217ee499d5e75.tar.gz
cpython-a3127e8e1149f20e780cf703fef217ee499d5e75.tar.bz2
added strop.translate(s, table)
Diffstat (limited to 'Modules/stropmodule.c')
-rw-r--r--Modules/stropmodule.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c
index 1cee66b..a82c313 100644
--- a/Modules/stropmodule.c
+++ b/Modules/stropmodule.c
@@ -503,6 +503,35 @@ strop_atof(self, args)
}
+static object *
+strop_translate(self, args)
+ object *self;
+ object *args;
+{
+ char *input, *table, *output;
+ int inlen, tablen;
+ object *result;
+ int i;
+
+ if (!newgetargs(args, "s#s#", &input, &inlen, &table, &tablen))
+ return NULL;
+ if (tablen != 256) {
+ err_setstr(ValueError,
+ "translation table must be 256 characters long");
+ return NULL;
+ }
+ result = newsizedstringobject((char *)NULL, inlen);
+ if (result == NULL)
+ return NULL;
+ output = getstringvalue(result);
+ for (i = 0; i < inlen; i++) {
+ int c = Py_CHARMASK(*input++);
+ *output++ = table[c];
+ }
+ return result;
+}
+
+
/* List of functions defined in the module */
static struct methodlist strop_methods[] = {
@@ -518,6 +547,7 @@ static struct methodlist strop_methods[] = {
{"splitfields", strop_splitfields, 1},
{"strip", strop_strip},
{"swapcase", strop_swapcase},
+ {"translate", strop_translate, 1},
{"upper", strop_upper},
{NULL, NULL} /* sentinel */
};