Patchwork [3,of,5,foldmap-in-C,V2] parsers: make _asciilower a generic _asciitransform function

login
register
mail settings
Submitter Siddharth Agarwal
Date April 1, 2015, 9 p.m.
Message ID <2dcf0e39c0e02e3160dc.1427922001@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8429/
State Accepted
Commit fe173106e7fea7f09bdb9a0093fbb06318a6306c
Headers show

Comments

Siddharth Agarwal - April 1, 2015, 9 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1427822897 25200
#      Tue Mar 31 10:28:17 2015 -0700
# Node ID 2dcf0e39c0e02e3160dc8586730922cb039c627f
# Parent  d00904680bc9a864604fa23e19480e60b7fc6feb
parsers: make _asciilower a generic _asciitransform function

We can now pass in whatever table we like. For example, an upcoming patch will
introduce asciiupper.

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -93,7 +93,8 @@ 
 	return ret;
 }
 
-static inline PyObject *_asciilower(PyObject *str_obj)
+static inline PyObject *_asciitransform(PyObject *str_obj,
+					const char table[128])
 {
 	char *str, *newstr;
 	Py_ssize_t i, len;
@@ -119,7 +120,7 @@ 
 			Py_XDECREF(err);
 			goto quit;
 		}
-		newstr[i] = lowertable[(unsigned char)c];
+		newstr[i] = table[(unsigned char)c];
 	}
 
 	ret = newobj;
@@ -134,7 +135,7 @@ 
 	PyObject *str_obj;
 	if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj))
 		return NULL;
-	return _asciilower(str_obj);
+	return _asciitransform(str_obj, lowertable);
 }
 
 /*