Mercurial > hg
comparison mercurial/parsers.c @ 24576:fe173106e7fe
parsers: make _asciilower a generic _asciitransform function
We can now pass in whatever table we like. For example, an upcoming patch will
introduce asciiupper.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 31 Mar 2015 10:28:17 -0700 |
parents | a62e957413f7 |
children | bf55df007535 |
comparison
equal
deleted
inserted
replaced
24575:a62e957413f7 | 24576:fe173106e7fe |
---|---|
91 } | 91 } |
92 | 92 |
93 return ret; | 93 return ret; |
94 } | 94 } |
95 | 95 |
96 static inline PyObject *_asciilower(PyObject *str_obj) | 96 static inline PyObject *_asciitransform(PyObject *str_obj, |
97 const char table[128]) | |
97 { | 98 { |
98 char *str, *newstr; | 99 char *str, *newstr; |
99 Py_ssize_t i, len; | 100 Py_ssize_t i, len; |
100 PyObject *newobj = NULL; | 101 PyObject *newobj = NULL; |
101 PyObject *ret = NULL; | 102 PyObject *ret = NULL; |
117 "unexpected code byte"); | 118 "unexpected code byte"); |
118 PyErr_SetObject(PyExc_UnicodeDecodeError, err); | 119 PyErr_SetObject(PyExc_UnicodeDecodeError, err); |
119 Py_XDECREF(err); | 120 Py_XDECREF(err); |
120 goto quit; | 121 goto quit; |
121 } | 122 } |
122 newstr[i] = lowertable[(unsigned char)c]; | 123 newstr[i] = table[(unsigned char)c]; |
123 } | 124 } |
124 | 125 |
125 ret = newobj; | 126 ret = newobj; |
126 Py_INCREF(ret); | 127 Py_INCREF(ret); |
127 quit: | 128 quit: |
132 static PyObject *asciilower(PyObject *self, PyObject *args) | 133 static PyObject *asciilower(PyObject *self, PyObject *args) |
133 { | 134 { |
134 PyObject *str_obj; | 135 PyObject *str_obj; |
135 if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj)) | 136 if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj)) |
136 return NULL; | 137 return NULL; |
137 return _asciilower(str_obj); | 138 return _asciitransform(str_obj, lowertable); |
138 } | 139 } |
139 | 140 |
140 /* | 141 /* |
141 * This code assumes that a manifest is stitched together with newline | 142 * This code assumes that a manifest is stitched together with newline |
142 * ('\n') characters. | 143 * ('\n') characters. |