summaryrefslogtreecommitdiff
path: root/numpy/core/src/ucsnarrow.c
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/src/ucsnarrow.c')
-rw-r--r--numpy/core/src/ucsnarrow.c124
1 files changed, 62 insertions, 62 deletions
diff --git a/numpy/core/src/ucsnarrow.c b/numpy/core/src/ucsnarrow.c
index 6eceadd0e..2d6fec082 100644
--- a/numpy/core/src/ucsnarrow.c
+++ b/numpy/core/src/ucsnarrow.c
@@ -11,27 +11,27 @@
is ucs4length + number of surrogate pairs found.
values above 0xffff are converted to surrogate pairs.
- */
+*/
static int
PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)
{
- register int i;
- int numucs2 = 0;
- PyArray_UCS4 chr;
- for (i=0; i<ucs4length; i++) {
- chr = *ucs4++;
- if (chr > 0xffff) {
- numucs2++;
- chr -= 0x10000L;
- *ucs2++ = 0xD800 + (Py_UNICODE) (chr >> 10);
- *ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);
- }
- else {
- *ucs2++ = (Py_UNICODE) chr;
- }
- numucs2++;
+ register int i;
+ int numucs2 = 0;
+ PyArray_UCS4 chr;
+ for (i=0; i<ucs4length; i++) {
+ chr = *ucs4++;
+ if (chr > 0xffff) {
+ numucs2++;
+ chr -= 0x10000L;
+ *ucs2++ = 0xD800 + (Py_UNICODE) (chr >> 10);
+ *ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);
+ }
+ else {
+ *ucs2++ = (Py_UNICODE) chr;
}
- return numucs2;
+ numucs2++;
+ }
+ return numucs2;
}
@@ -47,62 +47,62 @@ PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)
static int
PyUCS2Buffer_AsUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs2len, int ucs4len)
{
- register int i;
- register PyArray_UCS4 chr;
- register Py_UNICODE ch;
- register int numchars=0;
+ register int i;
+ register PyArray_UCS4 chr;
+ register Py_UNICODE ch;
+ register int numchars=0;
- for (i=0; (i < ucs2len) && (numchars < ucs4len); i++) {
- ch = *ucs2++;
- if (ch >= 0xd800 && ch <= 0xdfff) {
- /* surrogate pair */
- chr = ((PyArray_UCS4)(ch-0xd800)) << 10;
- chr += *ucs2++ + 0x2400; /* -0xdc00 + 0x10000 */
- i++;
- }
- else {
- chr = (PyArray_UCS4) ch;
- }
- *ucs4++ = chr;
- numchars++;
- }
- return numchars;
+ for (i=0; (i < ucs2len) && (numchars < ucs4len); i++) {
+ ch = *ucs2++;
+ if (ch >= 0xd800 && ch <= 0xdfff) {
+ /* surrogate pair */
+ chr = ((PyArray_UCS4)(ch-0xd800)) << 10;
+ chr += *ucs2++ + 0x2400; /* -0xdc00 + 0x10000 */
+ i++;
+ }
+ else {
+ chr = (PyArray_UCS4) ch;
+ }
+ *ucs4++ = chr;
+ numchars++;
+ }
+ return numchars;
}
static PyObject *
MyPyUnicode_New(int length)
{
- PyUnicodeObject *unicode;
- unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);
- if (unicode == NULL) return NULL;
- unicode->str = PyMem_NEW(Py_UNICODE, length+1);
- if (!unicode->str) {
- _Py_ForgetReference((PyObject *)unicode);
- PyObject_Del(unicode);
- return PyErr_NoMemory();
- }
- unicode->str[0] = 0;
- unicode->str[length] = 0;
- unicode->length = length;
- unicode->hash = -1;
- unicode->defenc = NULL;
- return (PyObject *)unicode;
+ PyUnicodeObject *unicode;
+ unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);
+ if (unicode == NULL) return NULL;
+ unicode->str = PyMem_NEW(Py_UNICODE, length+1);
+ if (!unicode->str) {
+ _Py_ForgetReference((PyObject *)unicode);
+ PyObject_Del(unicode);
+ return PyErr_NoMemory();
+ }
+ unicode->str[0] = 0;
+ unicode->str[length] = 0;
+ unicode->length = length;
+ unicode->hash = -1;
+ unicode->defenc = NULL;
+ return (PyObject *)unicode;
}
static int
MyPyUnicode_Resize(PyUnicodeObject *uni, int length)
{
- void *oldstr;
+ void *oldstr;
- oldstr = uni->str;
- PyMem_RESIZE(uni->str, Py_UNICODE, length+1);
- if (!uni->str) {
- uni->str = oldstr;
- PyErr_NoMemory();
- return -1;
- }
- uni->str[length] = 0;
- uni->length = length;
- return 0;
+ oldstr = uni->str;
+ PyMem_RESIZE(uni->str, Py_UNICODE, length+1);
+ if (!uni->str) {
+ uni->str = oldstr;
+ PyErr_NoMemory();
+ return -1;
+ }
+ uni->str[length] = 0;
+ uni->length = length;
+ return 0;
}