summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-02-09 02:08:49 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-02-09 02:08:49 +0000
commit520b1c94e456dacf814b1a2d1ff13e8133294cb1 (patch)
tree159055ca921ca6679e58a2d8ee97d410b8968467 /numpy/core
parent9a4d9271638c5a1e28dc21a2d92d8d5d16d2fbd5 (diff)
downloadnumpy-520b1c94e456dacf814b1a2d1ff13e8133294cb1.tar.gz
Add ucsnarrow.c code.
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/ucsnarrow.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/numpy/core/src/ucsnarrow.c b/numpy/core/src/ucsnarrow.c
new file mode 100644
index 000000000..8960026d5
--- /dev/null
+++ b/numpy/core/src/ucsnarrow.c
@@ -0,0 +1,40 @@
+
+/* the ucs2 buffer must be large enough to hold 2*ucs4length characters
+ due to the use of surrogate pairs.
+
+ The return value is the number of ucs2 bytes used-up which
+ 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 surrpairs = 0;
+ PyArray_UCS4 chr;
+ for (i=0; i<ucs4length; i++) {
+ chr = *ucs4++;
+ if (chr > 0xffff) {
+ surrpairs++;
+ chr -= 0x10000L;
+ *ucs2++ = 0xD800 + (Py_UNICODE) (chr >> 10);
+ *ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);
+ }
+ else {
+ *ucs2++ = (Py_UNICODE) (chr);
+ }
+ }
+ return ucs4length + surrpairs;
+}
+
+
+/* This converts a UCS2 buffer (from a Python unicode object)
+
+*/
+
+
+static int
+PyUCS2Buffer_AsUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length, int ucs2length)
+{
+}