Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 1 | /* ------------------------------------------------------------------------ |
| 2 | |
Ezio Melotti | ae735a7 | 2010-03-22 23:07:32 +0000 | [diff] [blame] | 3 | unicodedata -- Provides access to the Unicode 5.2 data base. |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 4 | |
Ezio Melotti | ae735a7 | 2010-03-22 23:07:32 +0000 | [diff] [blame] | 5 | Data was extracted from the Unicode 5.2 UnicodeData.txt file. |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 6 | |
Fredrik Lundh | cfcea49 | 2000-09-25 08:07:06 +0000 | [diff] [blame] | 7 | Written by Marc-Andre Lemburg (mal@lemburg.com). |
| 8 | Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com) |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 9 | Modified by Martin v. Löwis (martin@v.loewis.de) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 10 | |
Fredrik Lundh | cfcea49 | 2000-09-25 08:07:06 +0000 | [diff] [blame] | 11 | Copyright (c) Corporation for National Research Initiatives. |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 12 | |
| 13 | ------------------------------------------------------------------------ */ |
| 14 | |
| 15 | #include "Python.h" |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 16 | #include "ucnhash.h" |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 17 | #include "structmember.h" |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 18 | |
| 19 | /* character properties */ |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 20 | |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 21 | typedef struct { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 22 | const unsigned char category; /* index into |
| 23 | _PyUnicode_CategoryNames */ |
| 24 | const unsigned char combining; /* combining class value 0 - 255 */ |
| 25 | const unsigned char bidirectional; /* index into |
| 26 | _PyUnicode_BidirectionalNames */ |
| 27 | const unsigned char mirrored; /* true if mirrored in bidir mode */ |
| 28 | const unsigned char east_asian_width; /* index into |
| 29 | _PyUnicode_EastAsianWidth */ |
Antoine Pitrou | e988e28 | 2009-04-27 21:53:26 +0000 | [diff] [blame] | 30 | const unsigned char normalization_quick_check; /* see is_normalized() */ |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 31 | } _PyUnicode_DatabaseRecord; |
| 32 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 33 | typedef struct change_record { |
| 34 | /* sequence of fields should be the same as in merge_old_version */ |
| 35 | const unsigned char bidir_changed; |
| 36 | const unsigned char category_changed; |
| 37 | const unsigned char decimal_changed; |
Martin v. Löwis | 24329ba | 2008-09-10 13:38:12 +0000 | [diff] [blame] | 38 | const unsigned char mirrored_changed; |
Amaury Forgeot d'Arc | d0052d1 | 2009-10-06 19:56:32 +0000 | [diff] [blame] | 39 | const double numeric_changed; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 40 | } change_record; |
| 41 | |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 42 | /* data file generated by Tools/unicode/makeunicodedata.py */ |
| 43 | #include "unicodedata_db.h" |
| 44 | |
| 45 | static const _PyUnicode_DatabaseRecord* |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 46 | _getrecord_ex(Py_UCS4 code) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 47 | { |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 48 | int index; |
Neal Norwitz | e9c571f | 2003-02-28 03:14:37 +0000 | [diff] [blame] | 49 | if (code >= 0x110000) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 50 | index = 0; |
| 51 | else { |
| 52 | index = index1[(code>>SHIFT)]; |
| 53 | index = index2[(index<<SHIFT)+(code&((1<<SHIFT)-1))]; |
| 54 | } |
| 55 | |
| 56 | return &_PyUnicode_Database_Records[index]; |
| 57 | } |
| 58 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 59 | /* ------------- Previous-version API ------------------------------------- */ |
| 60 | typedef struct previous_version { |
| 61 | PyObject_HEAD |
| 62 | const char *name; |
| 63 | const change_record* (*getrecord)(Py_UCS4); |
| 64 | Py_UCS4 (*normalization)(Py_UCS4); |
| 65 | } PreviousDBVersion; |
| 66 | |
| 67 | #define get_old_record(self, v) ((((PreviousDBVersion*)self)->getrecord)(v)) |
| 68 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 69 | static PyMemberDef DB_members[] = { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 70 | {"unidata_version", T_STRING, offsetof(PreviousDBVersion, name), READONLY}, |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 71 | {NULL} |
| 72 | }; |
| 73 | |
Walter Dörwald | 6fc2382 | 2006-11-09 16:23:26 +0000 | [diff] [blame] | 74 | /* forward declaration */ |
Martin v. Löwis | 5bd7c02 | 2006-03-10 11:20:04 +0000 | [diff] [blame] | 75 | static PyTypeObject UCD_Type; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 76 | |
| 77 | static PyObject* |
| 78 | new_previous_version(const char*name, const change_record* (*getrecord)(Py_UCS4), |
| 79 | Py_UCS4 (*normalization)(Py_UCS4)) |
| 80 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 81 | PreviousDBVersion *self; |
| 82 | self = PyObject_New(PreviousDBVersion, &UCD_Type); |
| 83 | if (self == NULL) |
| 84 | return NULL; |
| 85 | self->name = name; |
| 86 | self->getrecord = getrecord; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 87 | self->normalization = normalization; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 88 | return (PyObject*)self; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 91 | |
| 92 | static Py_UCS4 getuchar(PyUnicodeObject *obj) |
| 93 | { |
| 94 | Py_UNICODE *v = PyUnicode_AS_UNICODE(obj); |
| 95 | |
| 96 | if (PyUnicode_GET_SIZE(obj) == 1) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 97 | return *v; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 98 | #ifndef Py_UNICODE_WIDE |
| 99 | else if ((PyUnicode_GET_SIZE(obj) == 2) && |
| 100 | (0xD800 <= v[0] && v[0] <= 0xDBFF) && |
| 101 | (0xDC00 <= v[1] && v[1] <= 0xDFFF)) |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 102 | return (((v[0] & 0x3FF)<<10) | (v[1] & 0x3FF)) + 0x10000; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 103 | #endif |
| 104 | PyErr_SetString(PyExc_TypeError, |
| 105 | "need a single Unicode character as parameter"); |
| 106 | return (Py_UCS4)-1; |
| 107 | } |
| 108 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 109 | /* --- Module API --------------------------------------------------------- */ |
| 110 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 111 | PyDoc_STRVAR(unicodedata_decimal__doc__, |
| 112 | "decimal(unichr[, default])\n\ |
| 113 | \n\ |
| 114 | Returns the decimal value assigned to the Unicode character unichr\n\ |
| 115 | as integer. If no such value is defined, default is returned, or, if\n\ |
| 116 | not given, ValueError is raised."); |
| 117 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 118 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 119 | unicodedata_decimal(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 120 | { |
| 121 | PyUnicodeObject *v; |
| 122 | PyObject *defobj = NULL; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 123 | int have_old = 0; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 124 | long rc; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 125 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 126 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 127 | if (!PyArg_ParseTuple(args, "O!|O:decimal", &PyUnicode_Type, &v, &defobj)) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 128 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 129 | c = getuchar(v); |
| 130 | if (c == (Py_UCS4)-1) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 131 | return NULL; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 132 | |
| 133 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 134 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 135 | if (old->category_changed == 0) { |
| 136 | /* unassigned */ |
| 137 | have_old = 1; |
| 138 | rc = -1; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 139 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 140 | else if (old->decimal_changed != 0xFF) { |
| 141 | have_old = 1; |
| 142 | rc = old->decimal_changed; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (!have_old) |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 147 | rc = Py_UNICODE_TODECIMAL(c); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 148 | if (rc < 0) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 149 | if (defobj == NULL) { |
| 150 | PyErr_SetString(PyExc_ValueError, |
| 151 | "not a decimal"); |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 152 | return NULL; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 153 | } |
| 154 | else { |
| 155 | Py_INCREF(defobj); |
| 156 | return defobj; |
| 157 | } |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 158 | } |
| 159 | return PyInt_FromLong(rc); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 162 | PyDoc_STRVAR(unicodedata_digit__doc__, |
| 163 | "digit(unichr[, default])\n\ |
| 164 | \n\ |
| 165 | Returns the digit value assigned to the Unicode character unichr as\n\ |
| 166 | integer. If no such value is defined, default is returned, or, if\n\ |
| 167 | not given, ValueError is raised."); |
| 168 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 169 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 170 | unicodedata_digit(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 171 | { |
| 172 | PyUnicodeObject *v; |
| 173 | PyObject *defobj = NULL; |
| 174 | long rc; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 175 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 176 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 177 | if (!PyArg_ParseTuple(args, "O!|O:digit", &PyUnicode_Type, &v, &defobj)) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 178 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 179 | c = getuchar(v); |
| 180 | if (c == (Py_UCS4)-1) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 181 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 182 | rc = Py_UNICODE_TODIGIT(c); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 183 | if (rc < 0) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 184 | if (defobj == NULL) { |
| 185 | PyErr_SetString(PyExc_ValueError, "not a digit"); |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 186 | return NULL; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 187 | } |
| 188 | else { |
| 189 | Py_INCREF(defobj); |
| 190 | return defobj; |
| 191 | } |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 192 | } |
| 193 | return PyInt_FromLong(rc); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 196 | PyDoc_STRVAR(unicodedata_numeric__doc__, |
| 197 | "numeric(unichr[, default])\n\ |
| 198 | \n\ |
| 199 | Returns the numeric value assigned to the Unicode character unichr\n\ |
| 200 | as float. If no such value is defined, default is returned, or, if\n\ |
| 201 | not given, ValueError is raised."); |
| 202 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 203 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 204 | unicodedata_numeric(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 205 | { |
| 206 | PyUnicodeObject *v; |
| 207 | PyObject *defobj = NULL; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 208 | int have_old = 0; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 209 | double rc; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 210 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 211 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 212 | if (!PyArg_ParseTuple(args, "O!|O:numeric", &PyUnicode_Type, &v, &defobj)) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 213 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 214 | c = getuchar(v); |
| 215 | if (c == (Py_UCS4)-1) |
| 216 | return NULL; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 217 | |
| 218 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 219 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 220 | if (old->category_changed == 0) { |
| 221 | /* unassigned */ |
| 222 | have_old = 1; |
Martin v. Löwis | d004fc8 | 2006-05-27 08:36:52 +0000 | [diff] [blame] | 223 | rc = -1.0; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 224 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 225 | else if (old->decimal_changed != 0xFF) { |
| 226 | have_old = 1; |
| 227 | rc = old->decimal_changed; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (!have_old) |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 232 | rc = Py_UNICODE_TONUMERIC(c); |
Martin v. Löwis | d004fc8 | 2006-05-27 08:36:52 +0000 | [diff] [blame] | 233 | if (rc == -1.0) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 234 | if (defobj == NULL) { |
| 235 | PyErr_SetString(PyExc_ValueError, "not a numeric character"); |
| 236 | return NULL; |
| 237 | } |
| 238 | else { |
| 239 | Py_INCREF(defobj); |
| 240 | return defobj; |
| 241 | } |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 242 | } |
| 243 | return PyFloat_FromDouble(rc); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 246 | PyDoc_STRVAR(unicodedata_category__doc__, |
| 247 | "category(unichr)\n\ |
| 248 | \n\ |
| 249 | Returns the general category assigned to the Unicode character\n\ |
| 250 | unichr as string."); |
| 251 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 252 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 253 | unicodedata_category(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 254 | { |
| 255 | PyUnicodeObject *v; |
| 256 | int index; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 257 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 258 | |
| 259 | if (!PyArg_ParseTuple(args, "O!:category", |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 260 | &PyUnicode_Type, &v)) |
| 261 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 262 | c = getuchar(v); |
| 263 | if (c == (Py_UCS4)-1) |
| 264 | return NULL; |
| 265 | index = (int) _getrecord_ex(c)->category; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 266 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 267 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 268 | if (old->category_changed != 0xFF) |
| 269 | index = old->category_changed; |
| 270 | } |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 271 | return PyString_FromString(_PyUnicode_CategoryNames[index]); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 274 | PyDoc_STRVAR(unicodedata_bidirectional__doc__, |
| 275 | "bidirectional(unichr)\n\ |
| 276 | \n\ |
Ezio Melotti | 67c563e | 2012-12-14 20:12:25 +0200 | [diff] [blame] | 277 | Returns the bidirectional class assigned to the Unicode character\n\ |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 278 | unichr as string. If no such value is defined, an empty string is\n\ |
| 279 | returned."); |
| 280 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 281 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 282 | unicodedata_bidirectional(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 283 | { |
| 284 | PyUnicodeObject *v; |
| 285 | int index; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 286 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 287 | |
| 288 | if (!PyArg_ParseTuple(args, "O!:bidirectional", |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 289 | &PyUnicode_Type, &v)) |
| 290 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 291 | c = getuchar(v); |
| 292 | if (c == (Py_UCS4)-1) |
| 293 | return NULL; |
| 294 | index = (int) _getrecord_ex(c)->bidirectional; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 295 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 296 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 297 | if (old->category_changed == 0) |
| 298 | index = 0; /* unassigned */ |
| 299 | else if (old->bidir_changed != 0xFF) |
| 300 | index = old->bidir_changed; |
| 301 | } |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 302 | return PyString_FromString(_PyUnicode_BidirectionalNames[index]); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 305 | PyDoc_STRVAR(unicodedata_combining__doc__, |
| 306 | "combining(unichr)\n\ |
| 307 | \n\ |
| 308 | Returns the canonical combining class assigned to the Unicode\n\ |
| 309 | character unichr as integer. Returns 0 if no combining class is\n\ |
| 310 | defined."); |
| 311 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 312 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 313 | unicodedata_combining(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 314 | { |
| 315 | PyUnicodeObject *v; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 316 | int index; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 317 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 318 | |
| 319 | if (!PyArg_ParseTuple(args, "O!:combining", |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 320 | &PyUnicode_Type, &v)) |
| 321 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 322 | c = getuchar(v); |
| 323 | if (c == (Py_UCS4)-1) |
| 324 | return NULL; |
| 325 | index = (int) _getrecord_ex(c)->combining; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 326 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 327 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 328 | if (old->category_changed == 0) |
| 329 | index = 0; /* unassigned */ |
| 330 | } |
| 331 | return PyInt_FromLong(index); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 334 | PyDoc_STRVAR(unicodedata_mirrored__doc__, |
| 335 | "mirrored(unichr)\n\ |
| 336 | \n\ |
| 337 | Returns the mirrored property assigned to the Unicode character\n\ |
| 338 | unichr as integer. Returns 1 if the character has been identified as\n\ |
| 339 | a \"mirrored\" character in bidirectional text, 0 otherwise."); |
| 340 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 341 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 342 | unicodedata_mirrored(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 343 | { |
| 344 | PyUnicodeObject *v; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 345 | int index; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 346 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 347 | |
| 348 | if (!PyArg_ParseTuple(args, "O!:mirrored", |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 349 | &PyUnicode_Type, &v)) |
| 350 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 351 | c = getuchar(v); |
| 352 | if (c == (Py_UCS4)-1) |
| 353 | return NULL; |
| 354 | index = (int) _getrecord_ex(c)->mirrored; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 355 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 356 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 357 | if (old->category_changed == 0) |
| 358 | index = 0; /* unassigned */ |
Martin v. Löwis | 24329ba | 2008-09-10 13:38:12 +0000 | [diff] [blame] | 359 | else if (old->mirrored_changed != 0xFF) |
| 360 | index = old->mirrored_changed; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 361 | } |
| 362 | return PyInt_FromLong(index); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 365 | PyDoc_STRVAR(unicodedata_east_asian_width__doc__, |
| 366 | "east_asian_width(unichr)\n\ |
| 367 | \n\ |
| 368 | Returns the east asian width assigned to the Unicode character\n\ |
| 369 | unichr as string."); |
| 370 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 371 | static PyObject * |
Hye-Shik Chang | e9ddfbb | 2004-08-04 07:38:35 +0000 | [diff] [blame] | 372 | unicodedata_east_asian_width(PyObject *self, PyObject *args) |
| 373 | { |
| 374 | PyUnicodeObject *v; |
| 375 | int index; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 376 | Py_UCS4 c; |
Hye-Shik Chang | e9ddfbb | 2004-08-04 07:38:35 +0000 | [diff] [blame] | 377 | |
| 378 | if (!PyArg_ParseTuple(args, "O!:east_asian_width", |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 379 | &PyUnicode_Type, &v)) |
| 380 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 381 | c = getuchar(v); |
| 382 | if (c == (Py_UCS4)-1) |
| 383 | return NULL; |
| 384 | index = (int) _getrecord_ex(c)->east_asian_width; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 385 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 386 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 387 | if (old->category_changed == 0) |
| 388 | index = 0; /* unassigned */ |
| 389 | } |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 390 | return PyString_FromString(_PyUnicode_EastAsianWidthNames[index]); |
Hye-Shik Chang | e9ddfbb | 2004-08-04 07:38:35 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 393 | PyDoc_STRVAR(unicodedata_decomposition__doc__, |
| 394 | "decomposition(unichr)\n\ |
| 395 | \n\ |
| 396 | Returns the character decomposition mapping assigned to the Unicode\n\ |
| 397 | character unichr as string. An empty string is returned in case no\n\ |
| 398 | such mapping is defined."); |
| 399 | |
Hye-Shik Chang | e9ddfbb | 2004-08-04 07:38:35 +0000 | [diff] [blame] | 400 | static PyObject * |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 401 | unicodedata_decomposition(PyObject *self, PyObject *args) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 402 | { |
| 403 | PyUnicodeObject *v; |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 404 | char decomp[256]; |
| 405 | int code, index, count, i; |
Neal Norwitz | 37f694f | 2006-07-27 04:04:50 +0000 | [diff] [blame] | 406 | unsigned int prefix_index; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 407 | Py_UCS4 c; |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 408 | |
| 409 | if (!PyArg_ParseTuple(args, "O!:decomposition", |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 410 | &PyUnicode_Type, &v)) |
| 411 | return NULL; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 412 | c = getuchar(v); |
| 413 | if (c == (Py_UCS4)-1) |
| 414 | return NULL; |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 415 | |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 416 | code = (int)c; |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 417 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 418 | if (self) { |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 419 | const change_record *old = get_old_record(self, c); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 420 | if (old->category_changed == 0) |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 421 | return PyString_FromString(""); /* unassigned */ |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Martin v. Löwis | 9def6a3 | 2002-10-18 16:11:54 +0000 | [diff] [blame] | 424 | if (code < 0 || code >= 0x110000) |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 425 | index = 0; |
| 426 | else { |
| 427 | index = decomp_index1[(code>>DECOMP_SHIFT)]; |
| 428 | index = decomp_index2[(index<<DECOMP_SHIFT)+ |
| 429 | (code&((1<<DECOMP_SHIFT)-1))]; |
| 430 | } |
| 431 | |
Tim Peters | 69b83b1 | 2001-11-30 07:23:05 +0000 | [diff] [blame] | 432 | /* high byte is number of hex bytes (usually one or two), low byte |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 433 | is prefix code (from*/ |
| 434 | count = decomp_data[index] >> 8; |
| 435 | |
| 436 | /* XXX: could allocate the PyString up front instead |
| 437 | (strlen(prefix) + 5 * count + 1 bytes) */ |
| 438 | |
Neal Norwitz | 37f694f | 2006-07-27 04:04:50 +0000 | [diff] [blame] | 439 | /* Based on how index is calculated above and decomp_data is generated |
| 440 | from Tools/unicode/makeunicodedata.py, it should not be possible |
| 441 | to overflow decomp_prefix. */ |
| 442 | prefix_index = decomp_data[index] & 255; |
| 443 | assert(prefix_index < (sizeof(decomp_prefix)/sizeof(*decomp_prefix))); |
| 444 | |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 445 | /* copy prefix */ |
Neal Norwitz | 37f694f | 2006-07-27 04:04:50 +0000 | [diff] [blame] | 446 | i = strlen(decomp_prefix[prefix_index]); |
| 447 | memcpy(decomp, decomp_prefix[prefix_index], i); |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 448 | |
| 449 | while (count-- > 0) { |
| 450 | if (i) |
| 451 | decomp[i++] = ' '; |
Tim Peters | 69b83b1 | 2001-11-30 07:23:05 +0000 | [diff] [blame] | 452 | assert((size_t)i < sizeof(decomp)); |
| 453 | PyOS_snprintf(decomp + i, sizeof(decomp) - i, "%04X", |
| 454 | decomp_data[++index]); |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 455 | i += strlen(decomp + i); |
| 456 | } |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 457 | |
Fredrik Lundh | 7b7dd10 | 2001-01-21 22:41:08 +0000 | [diff] [blame] | 458 | decomp[i] = '\0'; |
| 459 | |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 460 | return PyString_FromString(decomp); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Neal Norwitz | 88c9784 | 2006-04-17 00:36:29 +0000 | [diff] [blame] | 463 | static void |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 464 | get_decomp_record(PyObject *self, Py_UCS4 code, int *index, int *prefix, int *count) |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 465 | { |
Neal Norwitz | e9c571f | 2003-02-28 03:14:37 +0000 | [diff] [blame] | 466 | if (code >= 0x110000) { |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 467 | *index = 0; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 468 | } else if (self && get_old_record(self, code)->category_changed==0) { |
| 469 | /* unassigned in old version */ |
| 470 | *index = 0; |
| 471 | } |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 472 | else { |
| 473 | *index = decomp_index1[(code>>DECOMP_SHIFT)]; |
| 474 | *index = decomp_index2[(*index<<DECOMP_SHIFT)+ |
| 475 | (code&((1<<DECOMP_SHIFT)-1))]; |
| 476 | } |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 477 | |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 478 | /* high byte is number of hex bytes (usually one or two), low byte |
| 479 | is prefix code (from*/ |
| 480 | *count = decomp_data[*index] >> 8; |
| 481 | *prefix = decomp_data[*index] & 255; |
| 482 | |
| 483 | (*index)++; |
| 484 | } |
| 485 | |
| 486 | #define SBase 0xAC00 |
| 487 | #define LBase 0x1100 |
| 488 | #define VBase 0x1161 |
| 489 | #define TBase 0x11A7 |
| 490 | #define LCount 19 |
| 491 | #define VCount 21 |
| 492 | #define TCount 28 |
| 493 | #define NCount (VCount*TCount) |
| 494 | #define SCount (LCount*NCount) |
| 495 | |
| 496 | static PyObject* |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 497 | nfd_nfkd(PyObject *self, PyObject *input, int k) |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 498 | { |
| 499 | PyObject *result; |
| 500 | Py_UNICODE *i, *end, *o; |
| 501 | /* Longest decomposition in Unicode 3.2: U+FDFA */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 502 | Py_UNICODE stack[20]; |
Martin v. Löwis | 3c6e418 | 2006-04-13 06:36:31 +0000 | [diff] [blame] | 503 | Py_ssize_t space, isize; |
| 504 | int index, prefix, count, stackptr; |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 505 | unsigned char prev, cur; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 506 | |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 507 | stackptr = 0; |
| 508 | isize = PyUnicode_GET_SIZE(input); |
Ezio Melotti | 6d0f0f2 | 2013-08-26 01:31:30 +0300 | [diff] [blame] | 509 | /* Overallocate at most 10 characters. */ |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 510 | space = (isize > 10 ? 10 : isize) + isize; |
| 511 | result = PyUnicode_FromUnicode(NULL, space); |
| 512 | if (!result) |
| 513 | return NULL; |
| 514 | i = PyUnicode_AS_UNICODE(input); |
| 515 | end = i + isize; |
| 516 | o = PyUnicode_AS_UNICODE(result); |
| 517 | |
| 518 | while (i < end) { |
| 519 | stack[stackptr++] = *i++; |
| 520 | while(stackptr) { |
| 521 | Py_UNICODE code = stack[--stackptr]; |
Martin v. Löwis | d2171d2 | 2003-11-06 20:47:57 +0000 | [diff] [blame] | 522 | /* Hangul Decomposition adds three characters in |
Ezio Melotti | 419e23c | 2013-08-17 16:56:09 +0300 | [diff] [blame] | 523 | a single step, so we need at least that much room. */ |
Martin v. Löwis | d2171d2 | 2003-11-06 20:47:57 +0000 | [diff] [blame] | 524 | if (space < 3) { |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 525 | Py_ssize_t newsize = PyString_GET_SIZE(result) + 10; |
Martin v. Löwis | d2171d2 | 2003-11-06 20:47:57 +0000 | [diff] [blame] | 526 | space += 10; |
| 527 | if (PyUnicode_Resize(&result, newsize) == -1) |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 528 | return NULL; |
Martin v. Löwis | d2171d2 | 2003-11-06 20:47:57 +0000 | [diff] [blame] | 529 | o = PyUnicode_AS_UNICODE(result) + newsize - space; |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 530 | } |
| 531 | /* Hangul Decomposition. */ |
| 532 | if (SBase <= code && code < (SBase+SCount)) { |
| 533 | int SIndex = code - SBase; |
| 534 | int L = LBase + SIndex / NCount; |
| 535 | int V = VBase + (SIndex % NCount) / TCount; |
| 536 | int T = TBase + SIndex % TCount; |
| 537 | *o++ = L; |
| 538 | *o++ = V; |
| 539 | space -= 2; |
| 540 | if (T != TBase) { |
| 541 | *o++ = T; |
| 542 | space --; |
| 543 | } |
| 544 | continue; |
| 545 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 546 | /* normalization changes */ |
| 547 | if (self) { |
| 548 | Py_UCS4 value = ((PreviousDBVersion*)self)->normalization(code); |
| 549 | if (value != 0) { |
| 550 | stack[stackptr++] = value; |
| 551 | continue; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /* Other decompositions. */ |
| 556 | get_decomp_record(self, code, &index, &prefix, &count); |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 557 | |
| 558 | /* Copy character if it is not decomposable, or has a |
| 559 | compatibility decomposition, but we do NFD. */ |
| 560 | if (!count || (prefix && !k)) { |
| 561 | *o++ = code; |
| 562 | space--; |
| 563 | continue; |
| 564 | } |
| 565 | /* Copy decomposition onto the stack, in reverse |
| 566 | order. */ |
| 567 | while(count) { |
| 568 | code = decomp_data[index + (--count)]; |
| 569 | stack[stackptr++] = code; |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | /* Drop overallocation. Cannot fail. */ |
| 575 | PyUnicode_Resize(&result, PyUnicode_GET_SIZE(result) - space); |
| 576 | |
| 577 | /* Sort canonically. */ |
| 578 | i = PyUnicode_AS_UNICODE(result); |
| 579 | prev = _getrecord_ex(*i)->combining; |
| 580 | end = i + PyUnicode_GET_SIZE(result); |
| 581 | for (i++; i < end; i++) { |
| 582 | cur = _getrecord_ex(*i)->combining; |
| 583 | if (prev == 0 || cur == 0 || prev <= cur) { |
| 584 | prev = cur; |
| 585 | continue; |
| 586 | } |
| 587 | /* Non-canonical order. Need to switch *i with previous. */ |
| 588 | o = i - 1; |
| 589 | while (1) { |
| 590 | Py_UNICODE tmp = o[1]; |
| 591 | o[1] = o[0]; |
| 592 | o[0] = tmp; |
| 593 | o--; |
| 594 | if (o < PyUnicode_AS_UNICODE(result)) |
| 595 | break; |
| 596 | prev = _getrecord_ex(*o)->combining; |
| 597 | if (prev == 0 || prev <= cur) |
| 598 | break; |
| 599 | } |
| 600 | prev = _getrecord_ex(*i)->combining; |
| 601 | } |
| 602 | return result; |
| 603 | } |
| 604 | |
| 605 | static int |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 606 | find_nfc_index(PyObject *self, struct reindex* nfc, Py_UNICODE code) |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 607 | { |
| 608 | int index; |
| 609 | for (index = 0; nfc[index].start; index++) { |
| 610 | int start = nfc[index].start; |
| 611 | if (code < start) |
| 612 | return -1; |
| 613 | if (code <= start + nfc[index].count) { |
| 614 | int delta = code - start; |
| 615 | return nfc[index].index + delta; |
| 616 | } |
| 617 | } |
| 618 | return -1; |
| 619 | } |
| 620 | |
| 621 | static PyObject* |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 622 | nfc_nfkc(PyObject *self, PyObject *input, int k) |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 623 | { |
| 624 | PyObject *result; |
| 625 | Py_UNICODE *i, *i1, *o, *end; |
| 626 | int f,l,index,index1,comb; |
| 627 | Py_UNICODE code; |
| 628 | Py_UNICODE *skipped[20]; |
| 629 | int cskipped = 0; |
| 630 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 631 | result = nfd_nfkd(self, input, k); |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 632 | if (!result) |
| 633 | return NULL; |
| 634 | |
| 635 | /* We are going to modify result in-place. |
| 636 | If nfd_nfkd is changed to sometimes return the input, |
| 637 | this code needs to be reviewed. */ |
| 638 | assert(result != input); |
| 639 | |
| 640 | i = PyUnicode_AS_UNICODE(result); |
| 641 | end = i + PyUnicode_GET_SIZE(result); |
| 642 | o = PyUnicode_AS_UNICODE(result); |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 643 | |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 644 | again: |
| 645 | while (i < end) { |
| 646 | for (index = 0; index < cskipped; index++) { |
| 647 | if (skipped[index] == i) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 648 | /* *i character is skipped. |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 649 | Remove from list. */ |
| 650 | skipped[index] = skipped[cskipped-1]; |
| 651 | cskipped--; |
| 652 | i++; |
Martin v. Löwis | 2fb661f | 2002-12-07 14:56:36 +0000 | [diff] [blame] | 653 | goto again; /* continue while */ |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | /* Hangul Composition. We don't need to check for <LV,T> |
| 657 | pairs, since we always have decomposed data. */ |
| 658 | if (LBase <= *i && *i < (LBase+LCount) && |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 659 | i + 1 < end && |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 660 | VBase <= i[1] && i[1] <= (VBase+VCount)) { |
| 661 | int LIndex, VIndex; |
| 662 | LIndex = i[0] - LBase; |
| 663 | VIndex = i[1] - VBase; |
| 664 | code = SBase + (LIndex*VCount+VIndex)*TCount; |
| 665 | i+=2; |
| 666 | if (i < end && |
| 667 | TBase <= *i && *i <= (TBase+TCount)) { |
| 668 | code += *i-TBase; |
| 669 | i++; |
| 670 | } |
| 671 | *o++ = code; |
| 672 | continue; |
| 673 | } |
| 674 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 675 | f = find_nfc_index(self, nfc_first, *i); |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 676 | if (f == -1) { |
| 677 | *o++ = *i++; |
| 678 | continue; |
| 679 | } |
| 680 | /* Find next unblocked character. */ |
| 681 | i1 = i+1; |
| 682 | comb = 0; |
| 683 | while (i1 < end) { |
| 684 | int comb1 = _getrecord_ex(*i1)->combining; |
Alexander Belopolsky | dce6cf3 | 2010-12-28 15:47:56 +0000 | [diff] [blame] | 685 | if (comb) { |
| 686 | if (comb1 == 0) |
| 687 | break; |
| 688 | if (comb >= comb1) { |
| 689 | /* Character is blocked. */ |
| 690 | i1++; |
| 691 | continue; |
| 692 | } |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 693 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 694 | l = find_nfc_index(self, nfc_last, *i1); |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 695 | /* *i1 cannot be combined with *i. If *i1 |
| 696 | is a starter, we don't need to look further. |
| 697 | Otherwise, record the combining class. */ |
| 698 | if (l == -1) { |
| 699 | not_combinable: |
| 700 | if (comb1 == 0) |
| 701 | break; |
| 702 | comb = comb1; |
| 703 | i1++; |
| 704 | continue; |
| 705 | } |
| 706 | index = f*TOTAL_LAST + l; |
| 707 | index1 = comp_index[index >> COMP_SHIFT]; |
| 708 | code = comp_data[(index1<<COMP_SHIFT)+ |
| 709 | (index&((1<<COMP_SHIFT)-1))]; |
| 710 | if (code == 0) |
| 711 | goto not_combinable; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 712 | |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 713 | /* Replace the original character. */ |
| 714 | *i = code; |
| 715 | /* Mark the second character unused. */ |
Alexander Belopolsky | dce6cf3 | 2010-12-28 15:47:56 +0000 | [diff] [blame] | 716 | assert(cskipped < 20); |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 717 | skipped[cskipped++] = i1; |
| 718 | i1++; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 719 | f = find_nfc_index(self, nfc_first, *i); |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 720 | if (f == -1) |
| 721 | break; |
| 722 | } |
| 723 | *o++ = *i++; |
| 724 | } |
| 725 | if (o != end) |
| 726 | PyUnicode_Resize(&result, o - PyUnicode_AS_UNICODE(result)); |
| 727 | return result; |
| 728 | } |
Antoine Pitrou | e988e28 | 2009-04-27 21:53:26 +0000 | [diff] [blame] | 729 | |
| 730 | /* Return 1 if the input is certainly normalized, 0 if it might not be. */ |
| 731 | static int |
| 732 | is_normalized(PyObject *self, PyObject *input, int nfc, int k) |
| 733 | { |
| 734 | Py_UNICODE *i, *end; |
| 735 | unsigned char prev_combining = 0, quickcheck_mask; |
| 736 | |
| 737 | /* An older version of the database is requested, quickchecks must be |
| 738 | disabled. */ |
| 739 | if (self != NULL) |
| 740 | return 0; |
| 741 | |
| 742 | /* The two quickcheck bits at this shift mean 0=Yes, 1=Maybe, 2=No, |
| 743 | as described in http://unicode.org/reports/tr15/#Annex8. */ |
| 744 | quickcheck_mask = 3 << ((nfc ? 4 : 0) + (k ? 2 : 0)); |
| 745 | |
| 746 | i = PyUnicode_AS_UNICODE(input); |
| 747 | end = i + PyUnicode_GET_SIZE(input); |
| 748 | while (i < end) { |
| 749 | const _PyUnicode_DatabaseRecord *record = _getrecord_ex(*i++); |
| 750 | unsigned char combining = record->combining; |
| 751 | unsigned char quickcheck = record->normalization_quick_check; |
| 752 | |
| 753 | if (quickcheck & quickcheck_mask) |
| 754 | return 0; /* this string might need normalization */ |
| 755 | if (combining && prev_combining > combining) |
| 756 | return 0; /* non-canonical sort order, not normalized */ |
| 757 | prev_combining = combining; |
| 758 | } |
| 759 | return 1; /* certainly normalized */ |
| 760 | } |
| 761 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 762 | PyDoc_STRVAR(unicodedata_normalize__doc__, |
| 763 | "normalize(form, unistr)\n\ |
| 764 | \n\ |
| 765 | Return the normal form 'form' for the Unicode string unistr. Valid\n\ |
| 766 | values for form are 'NFC', 'NFKC', 'NFD', and 'NFKD'."); |
| 767 | |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 768 | static PyObject* |
| 769 | unicodedata_normalize(PyObject *self, PyObject *args) |
| 770 | { |
| 771 | char *form; |
| 772 | PyObject *input; |
| 773 | |
Hye-Shik Chang | 69dc1c8 | 2004-07-15 04:30:25 +0000 | [diff] [blame] | 774 | if(!PyArg_ParseTuple(args, "sO!:normalize", |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 775 | &form, &PyUnicode_Type, &input)) |
| 776 | return NULL; |
| 777 | |
Martin v. Löwis | 61e40bd | 2004-04-17 19:36:48 +0000 | [diff] [blame] | 778 | if (PyUnicode_GetSize(input) == 0) { |
| 779 | /* Special case empty input strings, since resizing |
| 780 | them later would cause internal errors. */ |
| 781 | Py_INCREF(input); |
| 782 | return input; |
| 783 | } |
| 784 | |
Antoine Pitrou | e988e28 | 2009-04-27 21:53:26 +0000 | [diff] [blame] | 785 | if (strcmp(form, "NFC") == 0) { |
| 786 | if (is_normalized(self, input, 1, 0)) { |
| 787 | Py_INCREF(input); |
| 788 | return input; |
| 789 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 790 | return nfc_nfkc(self, input, 0); |
Antoine Pitrou | e988e28 | 2009-04-27 21:53:26 +0000 | [diff] [blame] | 791 | } |
| 792 | if (strcmp(form, "NFKC") == 0) { |
| 793 | if (is_normalized(self, input, 1, 1)) { |
| 794 | Py_INCREF(input); |
| 795 | return input; |
| 796 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 797 | return nfc_nfkc(self, input, 1); |
Antoine Pitrou | e988e28 | 2009-04-27 21:53:26 +0000 | [diff] [blame] | 798 | } |
| 799 | if (strcmp(form, "NFD") == 0) { |
| 800 | if (is_normalized(self, input, 0, 0)) { |
| 801 | Py_INCREF(input); |
| 802 | return input; |
| 803 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 804 | return nfd_nfkd(self, input, 0); |
Antoine Pitrou | e988e28 | 2009-04-27 21:53:26 +0000 | [diff] [blame] | 805 | } |
| 806 | if (strcmp(form, "NFKD") == 0) { |
| 807 | if (is_normalized(self, input, 0, 1)) { |
| 808 | Py_INCREF(input); |
| 809 | return input; |
| 810 | } |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 811 | return nfd_nfkd(self, input, 1); |
Antoine Pitrou | e988e28 | 2009-04-27 21:53:26 +0000 | [diff] [blame] | 812 | } |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 813 | PyErr_SetString(PyExc_ValueError, "invalid normalization form"); |
| 814 | return NULL; |
| 815 | } |
| 816 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 817 | /* -------------------------------------------------------------------- */ |
| 818 | /* unicode character name tables */ |
| 819 | |
| 820 | /* data file generated by Tools/unicode/makeunicodedata.py */ |
| 821 | #include "unicodename_db.h" |
| 822 | |
| 823 | /* -------------------------------------------------------------------- */ |
| 824 | /* database code (cut and pasted from the unidb package) */ |
| 825 | |
| 826 | static unsigned long |
Fredrik Lundh | b95896b | 2001-02-18 22:06:17 +0000 | [diff] [blame] | 827 | _gethash(const char *s, int len, int scale) |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 828 | { |
| 829 | int i; |
| 830 | unsigned long h = 0; |
| 831 | unsigned long ix; |
| 832 | for (i = 0; i < len; i++) { |
Antoine Pitrou | 44b3b54 | 2011-10-04 13:55:37 +0200 | [diff] [blame] | 833 | h = (h * scale) + (unsigned char) Py_TOUPPER(Py_CHARMASK(s[i])); |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 834 | ix = h & 0xff000000; |
| 835 | if (ix) |
| 836 | h = (h ^ ((ix>>24) & 0xff)) & 0x00ffffff; |
| 837 | } |
| 838 | return h; |
| 839 | } |
| 840 | |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 841 | static char *hangul_syllables[][3] = { |
| 842 | { "G", "A", "" }, |
| 843 | { "GG", "AE", "G" }, |
| 844 | { "N", "YA", "GG" }, |
| 845 | { "D", "YAE", "GS" }, |
| 846 | { "DD", "EO", "N", }, |
| 847 | { "R", "E", "NJ" }, |
| 848 | { "M", "YEO", "NH" }, |
| 849 | { "B", "YE", "D" }, |
| 850 | { "BB", "O", "L" }, |
| 851 | { "S", "WA", "LG" }, |
| 852 | { "SS", "WAE", "LM" }, |
| 853 | { "", "OE", "LB" }, |
| 854 | { "J", "YO", "LS" }, |
| 855 | { "JJ", "U", "LT" }, |
| 856 | { "C", "WEO", "LP" }, |
| 857 | { "K", "WE", "LH" }, |
| 858 | { "T", "WI", "M" }, |
| 859 | { "P", "YU", "B" }, |
| 860 | { "H", "EU", "BS" }, |
| 861 | { 0, "YI", "S" }, |
| 862 | { 0, "I", "SS" }, |
| 863 | { 0, 0, "NG" }, |
| 864 | { 0, 0, "J" }, |
| 865 | { 0, 0, "C" }, |
| 866 | { 0, 0, "K" }, |
| 867 | { 0, 0, "T" }, |
| 868 | { 0, 0, "P" }, |
| 869 | { 0, 0, "H" } |
| 870 | }; |
| 871 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 872 | static int |
Martin v. Löwis | 8d93ca1 | 2002-11-23 22:10:29 +0000 | [diff] [blame] | 873 | is_unified_ideograph(Py_UCS4 code) |
| 874 | { |
| 875 | return ( |
| 876 | (0x3400 <= code && code <= 0x4DB5) || /* CJK Ideograph Extension A */ |
Martin v. Löwis | e03c778 | 2010-11-22 10:53:46 +0000 | [diff] [blame] | 877 | (0x4E00 <= code && code <= 0x9FCB) || /* CJK Ideograph, Unicode 5.2 */ |
| 878 | (0x20000 <= code && code <= 0x2A6D6) || /* CJK Ideograph Extension B */ |
| 879 | (0x2A700 <= code && code <= 0x2B734)); /* CJK Ideograph Extension C */ |
Martin v. Löwis | 8d93ca1 | 2002-11-23 22:10:29 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | static int |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 883 | _getucname(PyObject *self, Py_UCS4 code, char* buffer, int buflen) |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 884 | { |
| 885 | int offset; |
| 886 | int i; |
| 887 | int word; |
| 888 | unsigned char* w; |
| 889 | |
Martin v. Löwis | c350912 | 2006-03-11 12:16:23 +0000 | [diff] [blame] | 890 | if (code >= 0x110000) |
| 891 | return 0; |
| 892 | |
| 893 | if (self) { |
| 894 | const change_record *old = get_old_record(self, code); |
| 895 | if (old->category_changed == 0) { |
| 896 | /* unassigned */ |
| 897 | return 0; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 898 | } |
Martin v. Löwis | c350912 | 2006-03-11 12:16:23 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Martin v. Löwis | 2f4be4e | 2002-11-23 17:11:06 +0000 | [diff] [blame] | 901 | if (SBase <= code && code < SBase+SCount) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 902 | /* Hangul syllable. */ |
| 903 | int SIndex = code - SBase; |
| 904 | int L = SIndex / NCount; |
| 905 | int V = (SIndex % NCount) / TCount; |
| 906 | int T = SIndex % TCount; |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 907 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 908 | if (buflen < 27) |
| 909 | /* Worst case: HANGUL SYLLABLE <10chars>. */ |
| 910 | return 0; |
| 911 | strcpy(buffer, "HANGUL SYLLABLE "); |
| 912 | buffer += 16; |
| 913 | strcpy(buffer, hangul_syllables[L][0]); |
| 914 | buffer += strlen(hangul_syllables[L][0]); |
| 915 | strcpy(buffer, hangul_syllables[V][1]); |
| 916 | buffer += strlen(hangul_syllables[V][1]); |
| 917 | strcpy(buffer, hangul_syllables[T][2]); |
| 918 | buffer += strlen(hangul_syllables[T][2]); |
| 919 | *buffer = '\0'; |
| 920 | return 1; |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Martin v. Löwis | 8d93ca1 | 2002-11-23 22:10:29 +0000 | [diff] [blame] | 923 | if (is_unified_ideograph(code)) { |
Martin v. Löwis | ef7fe2e | 2002-11-23 18:01:32 +0000 | [diff] [blame] | 924 | if (buflen < 28) |
| 925 | /* Worst case: CJK UNIFIED IDEOGRAPH-20000 */ |
| 926 | return 0; |
| 927 | sprintf(buffer, "CJK UNIFIED IDEOGRAPH-%X", code); |
| 928 | return 1; |
| 929 | } |
| 930 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 931 | /* get offset into phrasebook */ |
| 932 | offset = phrasebook_offset1[(code>>phrasebook_shift)]; |
| 933 | offset = phrasebook_offset2[(offset<<phrasebook_shift) + |
| 934 | (code&((1<<phrasebook_shift)-1))]; |
| 935 | if (!offset) |
| 936 | return 0; |
| 937 | |
| 938 | i = 0; |
| 939 | |
| 940 | for (;;) { |
| 941 | /* get word index */ |
| 942 | word = phrasebook[offset] - phrasebook_short; |
| 943 | if (word >= 0) { |
| 944 | word = (word << 8) + phrasebook[offset+1]; |
| 945 | offset += 2; |
| 946 | } else |
| 947 | word = phrasebook[offset++]; |
| 948 | if (i) { |
| 949 | if (i > buflen) |
| 950 | return 0; /* buffer overflow */ |
| 951 | buffer[i++] = ' '; |
| 952 | } |
| 953 | /* copy word string from lexicon. the last character in the |
| 954 | word has bit 7 set. the last word in a string ends with |
| 955 | 0x80 */ |
| 956 | w = lexicon + lexicon_offset[word]; |
| 957 | while (*w < 128) { |
| 958 | if (i >= buflen) |
| 959 | return 0; /* buffer overflow */ |
| 960 | buffer[i++] = *w++; |
| 961 | } |
| 962 | if (i >= buflen) |
| 963 | return 0; /* buffer overflow */ |
| 964 | buffer[i++] = *w & 127; |
| 965 | if (*w == 128) |
| 966 | break; /* end of word */ |
| 967 | } |
| 968 | |
| 969 | return 1; |
| 970 | } |
| 971 | |
| 972 | static int |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 973 | _cmpname(PyObject *self, int code, const char* name, int namelen) |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 974 | { |
| 975 | /* check if code corresponds to the given name */ |
| 976 | int i; |
| 977 | char buffer[NAME_MAXLEN]; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 978 | if (!_getucname(self, code, buffer, sizeof(buffer))) |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 979 | return 0; |
| 980 | for (i = 0; i < namelen; i++) { |
Antoine Pitrou | 44b3b54 | 2011-10-04 13:55:37 +0200 | [diff] [blame] | 981 | if (Py_TOUPPER(Py_CHARMASK(name[i])) != buffer[i]) |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 982 | return 0; |
| 983 | } |
| 984 | return buffer[namelen] == '\0'; |
| 985 | } |
| 986 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 987 | static void |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 988 | find_syllable(const char *str, int *len, int *pos, int count, int column) |
| 989 | { |
| 990 | int i, len1; |
| 991 | *len = -1; |
| 992 | for (i = 0; i < count; i++) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 993 | char *s = hangul_syllables[i][column]; |
| 994 | len1 = strlen(s); |
| 995 | if (len1 <= *len) |
| 996 | continue; |
| 997 | if (strncmp(str, s, len1) == 0) { |
| 998 | *len = len1; |
| 999 | *pos = i; |
| 1000 | } |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 1001 | } |
| 1002 | if (*len == -1) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1003 | *len = 0; |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1007 | static int |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 1008 | _getcode(PyObject* self, const char* name, int namelen, Py_UCS4* code) |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1009 | { |
| 1010 | unsigned int h, v; |
| 1011 | unsigned int mask = code_size-1; |
| 1012 | unsigned int i, incr; |
| 1013 | |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 1014 | /* Check for hangul syllables. */ |
| 1015 | if (strncmp(name, "HANGUL SYLLABLE ", 16) == 0) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1016 | int len, L = -1, V = -1, T = -1; |
| 1017 | const char *pos = name + 16; |
| 1018 | find_syllable(pos, &len, &L, LCount, 0); |
| 1019 | pos += len; |
| 1020 | find_syllable(pos, &len, &V, VCount, 1); |
| 1021 | pos += len; |
| 1022 | find_syllable(pos, &len, &T, TCount, 2); |
| 1023 | pos += len; |
| 1024 | if (L != -1 && V != -1 && T != -1 && pos-name == namelen) { |
| 1025 | *code = SBase + (L*VCount+V)*TCount + T; |
| 1026 | return 1; |
| 1027 | } |
Martin v. Löwis | ef7fe2e | 2002-11-23 18:01:32 +0000 | [diff] [blame] | 1028 | /* Otherwise, it's an illegal syllable name. */ |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | /* Check for unified ideographs. */ |
| 1033 | if (strncmp(name, "CJK UNIFIED IDEOGRAPH-", 22) == 0) { |
| 1034 | /* Four or five hexdigits must follow. */ |
| 1035 | v = 0; |
| 1036 | name += 22; |
| 1037 | namelen -= 22; |
| 1038 | if (namelen != 4 && namelen != 5) |
| 1039 | return 0; |
| 1040 | while (namelen--) { |
| 1041 | v *= 16; |
| 1042 | if (*name >= '0' && *name <= '9') |
| 1043 | v += *name - '0'; |
| 1044 | else if (*name >= 'A' && *name <= 'F') |
| 1045 | v += *name - 'A' + 10; |
| 1046 | else |
| 1047 | return 0; |
| 1048 | name++; |
| 1049 | } |
Martin v. Löwis | 8d93ca1 | 2002-11-23 22:10:29 +0000 | [diff] [blame] | 1050 | if (!is_unified_ideograph(v)) |
| 1051 | return 0; |
Martin v. Löwis | ef7fe2e | 2002-11-23 18:01:32 +0000 | [diff] [blame] | 1052 | *code = v; |
| 1053 | return 1; |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1056 | /* the following is the same as python's dictionary lookup, with |
| 1057 | only minor changes. see the makeunicodedata script for more |
| 1058 | details */ |
| 1059 | |
Fredrik Lundh | b95896b | 2001-02-18 22:06:17 +0000 | [diff] [blame] | 1060 | h = (unsigned int) _gethash(name, namelen, code_magic); |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1061 | i = (~h) & mask; |
| 1062 | v = code_hash[i]; |
| 1063 | if (!v) |
| 1064 | return 0; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 1065 | if (_cmpname(self, v, name, namelen)) { |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1066 | *code = v; |
| 1067 | return 1; |
| 1068 | } |
| 1069 | incr = (h ^ (h >> 3)) & mask; |
| 1070 | if (!incr) |
| 1071 | incr = mask; |
| 1072 | for (;;) { |
| 1073 | i = (i + incr) & mask; |
| 1074 | v = code_hash[i]; |
| 1075 | if (!v) |
Fredrik Lundh | ae76367 | 2001-02-18 11:41:49 +0000 | [diff] [blame] | 1076 | return 0; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 1077 | if (_cmpname(self, v, name, namelen)) { |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1078 | *code = v; |
| 1079 | return 1; |
| 1080 | } |
| 1081 | incr = incr << 1; |
| 1082 | if (incr > mask) |
| 1083 | incr = incr ^ code_poly; |
| 1084 | } |
| 1085 | } |
| 1086 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1087 | static const _PyUnicode_Name_CAPI hashAPI = |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1088 | { |
| 1089 | sizeof(_PyUnicode_Name_CAPI), |
Andrew MacIntyre | 74a3bec | 2002-06-13 11:55:14 +0000 | [diff] [blame] | 1090 | _getucname, |
Fredrik Lundh | b95896b | 2001-02-18 22:06:17 +0000 | [diff] [blame] | 1091 | _getcode |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1092 | }; |
| 1093 | |
| 1094 | /* -------------------------------------------------------------------- */ |
| 1095 | /* Python bindings */ |
| 1096 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 1097 | PyDoc_STRVAR(unicodedata_name__doc__, |
| 1098 | "name(unichr[, default])\n\ |
| 1099 | Returns the name assigned to the Unicode character unichr as a\n\ |
| 1100 | string. If no name is defined, default is returned, or, if not\n\ |
| 1101 | given, ValueError is raised."); |
| 1102 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1103 | static PyObject * |
| 1104 | unicodedata_name(PyObject* self, PyObject* args) |
| 1105 | { |
| 1106 | char name[NAME_MAXLEN]; |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 1107 | Py_UCS4 c; |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1108 | |
| 1109 | PyUnicodeObject* v; |
| 1110 | PyObject* defobj = NULL; |
| 1111 | if (!PyArg_ParseTuple(args, "O!|O:name", &PyUnicode_Type, &v, &defobj)) |
| 1112 | return NULL; |
| 1113 | |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 1114 | c = getuchar(v); |
| 1115 | if (c == (Py_UCS4)-1) |
| 1116 | return NULL; |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1117 | |
Walter Dörwald | a2a89a8 | 2008-06-02 20:36:03 +0000 | [diff] [blame] | 1118 | if (!_getucname(self, c, name, sizeof(name))) { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1119 | if (defobj == NULL) { |
| 1120 | PyErr_SetString(PyExc_ValueError, "no such name"); |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1121 | return NULL; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1122 | } |
| 1123 | else { |
| 1124 | Py_INCREF(defobj); |
| 1125 | return defobj; |
| 1126 | } |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | return Py_BuildValue("s", name); |
| 1130 | } |
| 1131 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 1132 | PyDoc_STRVAR(unicodedata_lookup__doc__, |
| 1133 | "lookup(name)\n\ |
| 1134 | \n\ |
| 1135 | Look up character by name. If a character with the\n\ |
| 1136 | given name is found, return the corresponding Unicode\n\ |
| 1137 | character. If not found, KeyError is raised."); |
| 1138 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1139 | static PyObject * |
| 1140 | unicodedata_lookup(PyObject* self, PyObject* args) |
| 1141 | { |
| 1142 | Py_UCS4 code; |
Martin v. Löwis | f1e0b3f | 2007-07-28 07:03:05 +0000 | [diff] [blame] | 1143 | Py_UNICODE str[2]; |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1144 | |
| 1145 | char* name; |
| 1146 | int namelen; |
| 1147 | if (!PyArg_ParseTuple(args, "s#:lookup", &name, &namelen)) |
| 1148 | return NULL; |
| 1149 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 1150 | if (!_getcode(self, name, namelen, &code)) { |
Martin v. Löwis | f1e0b3f | 2007-07-28 07:03:05 +0000 | [diff] [blame] | 1151 | PyErr_Format(PyExc_KeyError, "undefined character name '%s'", |
| 1152 | name); |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1153 | return NULL; |
| 1154 | } |
| 1155 | |
Martin v. Löwis | f1e0b3f | 2007-07-28 07:03:05 +0000 | [diff] [blame] | 1156 | #ifndef Py_UNICODE_WIDE |
| 1157 | if (code >= 0x10000) { |
| 1158 | str[0] = 0xd800 + ((code - 0x10000) >> 10); |
| 1159 | str[1] = 0xdc00 + ((code - 0x10000) & 0x3ff); |
| 1160 | return PyUnicode_FromUnicode(str, 2); |
| 1161 | } |
| 1162 | #endif |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1163 | str[0] = (Py_UNICODE) code; |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1164 | return PyUnicode_FromUnicode(str, 1); |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 1167 | /* XXX Add doc strings. */ |
| 1168 | |
| 1169 | static PyMethodDef unicodedata_functions[] = { |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 1170 | {"decimal", unicodedata_decimal, METH_VARARGS, unicodedata_decimal__doc__}, |
| 1171 | {"digit", unicodedata_digit, METH_VARARGS, unicodedata_digit__doc__}, |
| 1172 | {"numeric", unicodedata_numeric, METH_VARARGS, unicodedata_numeric__doc__}, |
| 1173 | {"category", unicodedata_category, METH_VARARGS, |
| 1174 | unicodedata_category__doc__}, |
| 1175 | {"bidirectional", unicodedata_bidirectional, METH_VARARGS, |
| 1176 | unicodedata_bidirectional__doc__}, |
| 1177 | {"combining", unicodedata_combining, METH_VARARGS, |
| 1178 | unicodedata_combining__doc__}, |
| 1179 | {"mirrored", unicodedata_mirrored, METH_VARARGS, |
| 1180 | unicodedata_mirrored__doc__}, |
| 1181 | {"east_asian_width", unicodedata_east_asian_width, METH_VARARGS, |
| 1182 | unicodedata_east_asian_width__doc__}, |
| 1183 | {"decomposition", unicodedata_decomposition, METH_VARARGS, |
| 1184 | unicodedata_decomposition__doc__}, |
| 1185 | {"name", unicodedata_name, METH_VARARGS, unicodedata_name__doc__}, |
| 1186 | {"lookup", unicodedata_lookup, METH_VARARGS, unicodedata_lookup__doc__}, |
| 1187 | {"normalize", unicodedata_normalize, METH_VARARGS, |
| 1188 | unicodedata_normalize__doc__}, |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1189 | {NULL, NULL} /* sentinel */ |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 1190 | }; |
| 1191 | |
Martin v. Löwis | 5bd7c02 | 2006-03-10 11:20:04 +0000 | [diff] [blame] | 1192 | static PyTypeObject UCD_Type = { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1193 | /* The ob_type field must be initialized in the module init function |
| 1194 | * to be portable to Windows without using C++. */ |
| 1195 | PyVarObject_HEAD_INIT(NULL, 0) |
| 1196 | "unicodedata.UCD", /*tp_name*/ |
| 1197 | sizeof(PreviousDBVersion), /*tp_basicsize*/ |
| 1198 | 0, /*tp_itemsize*/ |
| 1199 | /* methods */ |
| 1200 | (destructor)PyObject_Del, /*tp_dealloc*/ |
| 1201 | 0, /*tp_print*/ |
| 1202 | 0, /*tp_getattr*/ |
| 1203 | 0, /*tp_setattr*/ |
| 1204 | 0, /*tp_compare*/ |
| 1205 | 0, /*tp_repr*/ |
| 1206 | 0, /*tp_as_number*/ |
| 1207 | 0, /*tp_as_sequence*/ |
| 1208 | 0, /*tp_as_mapping*/ |
| 1209 | 0, /*tp_hash*/ |
Martin v. Löwis | 5bd7c02 | 2006-03-10 11:20:04 +0000 | [diff] [blame] | 1210 | 0, /*tp_call*/ |
| 1211 | 0, /*tp_str*/ |
| 1212 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 1213 | 0, /*tp_setattro*/ |
| 1214 | 0, /*tp_as_buffer*/ |
| 1215 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1216 | 0, /*tp_doc*/ |
| 1217 | 0, /*tp_traverse*/ |
| 1218 | 0, /*tp_clear*/ |
| 1219 | 0, /*tp_richcompare*/ |
| 1220 | 0, /*tp_weaklistoffset*/ |
| 1221 | 0, /*tp_iter*/ |
| 1222 | 0, /*tp_iternext*/ |
| 1223 | unicodedata_functions, /*tp_methods*/ |
| 1224 | DB_members, /*tp_members*/ |
| 1225 | 0, /*tp_getset*/ |
| 1226 | 0, /*tp_base*/ |
| 1227 | 0, /*tp_dict*/ |
| 1228 | 0, /*tp_descr_get*/ |
| 1229 | 0, /*tp_descr_set*/ |
| 1230 | 0, /*tp_dictoffset*/ |
| 1231 | 0, /*tp_init*/ |
| 1232 | 0, /*tp_alloc*/ |
| 1233 | 0, /*tp_new*/ |
| 1234 | 0, /*tp_free*/ |
| 1235 | 0, /*tp_is_gc*/ |
| 1236 | }; |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 1237 | |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 1238 | PyDoc_STRVAR(unicodedata_docstring, |
| 1239 | "This module provides access to the Unicode Character Database which\n\ |
| 1240 | defines character properties for all Unicode characters. The data in\n\ |
| 1241 | this database is based on the UnicodeData.txt file version\n\ |
Ezio Melotti | ae735a7 | 2010-03-22 23:07:32 +0000 | [diff] [blame] | 1242 | 5.2.0 which is publically available from ftp://ftp.unicode.org/.\n\ |
Hye-Shik Chang | cf18a5d | 2005-04-04 16:32:07 +0000 | [diff] [blame] | 1243 | \n\ |
| 1244 | The module uses the same names and symbols as defined by the\n\ |
Ezio Melotti | 0d0b80b | 2010-03-23 00:38:12 +0000 | [diff] [blame] | 1245 | UnicodeData File Format 5.2.0 (see\n\ |
| 1246 | http://www.unicode.org/reports/tr44/tr44-4.html)."); |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1247 | |
Mark Hammond | 62b1ab1 | 2002-07-23 06:31:15 +0000 | [diff] [blame] | 1248 | PyMODINIT_FUNC |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 1249 | initunicodedata(void) |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 1250 | { |
Fred Drake | a2bd8d3 | 2002-04-03 21:39:26 +0000 | [diff] [blame] | 1251 | PyObject *m, *v; |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1252 | |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 1253 | Py_TYPE(&UCD_Type) = &PyType_Type; |
Martin v. Löwis | 5bd7c02 | 2006-03-10 11:20:04 +0000 | [diff] [blame] | 1254 | |
Fred Drake | f585bef | 2001-03-03 19:41:55 +0000 | [diff] [blame] | 1255 | m = Py_InitModule3( |
| 1256 | "unicodedata", unicodedata_functions, unicodedata_docstring); |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1257 | if (!m) |
| 1258 | return; |
| 1259 | |
Martin v. Löwis | b5c980b | 2002-11-25 09:13:37 +0000 | [diff] [blame] | 1260 | PyModule_AddStringConstant(m, "unidata_version", UNIDATA_VERSION); |
Martin v. Löwis | 0e2f9b2 | 2006-03-10 11:29:32 +0000 | [diff] [blame] | 1261 | Py_INCREF(&UCD_Type); |
Martin v. Löwis | 5bd7c02 | 2006-03-10 11:20:04 +0000 | [diff] [blame] | 1262 | PyModule_AddObject(m, "UCD", (PyObject*)&UCD_Type); |
Martin v. Löwis | b5c980b | 2002-11-25 09:13:37 +0000 | [diff] [blame] | 1263 | |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 1264 | /* Previous versions */ |
| 1265 | v = new_previous_version("3.2.0", get_change_3_2_0, normalization_3_2_0); |
| 1266 | if (v != NULL) |
Martin v. Löwis | 5bd7c02 | 2006-03-10 11:20:04 +0000 | [diff] [blame] | 1267 | PyModule_AddObject(m, "ucd_3_2_0", v); |
Martin v. Löwis | 480f1bb | 2006-03-09 23:38:20 +0000 | [diff] [blame] | 1268 | |
Fredrik Lundh | 06d1268 | 2001-01-24 07:59:11 +0000 | [diff] [blame] | 1269 | /* Export C API */ |
Larry Hastings | 402b73f | 2010-03-25 00:54:54 +0000 | [diff] [blame] | 1270 | v = PyCapsule_New((void *)&hashAPI, PyUnicodeData_CAPSULE_NAME, NULL); |
Fred Drake | a2bd8d3 | 2002-04-03 21:39:26 +0000 | [diff] [blame] | 1271 | if (v != NULL) |
| 1272 | PyModule_AddObject(m, "ucnhash_CAPI", v); |
Guido van Rossum | 2a70a3a | 2000-03-10 23:10:21 +0000 | [diff] [blame] | 1273 | } |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 1274 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 1275 | /* |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 1276 | Local variables: |
| 1277 | c-basic-offset: 4 |
Martin v. Löwis | 677bde2 | 2002-11-23 22:08:15 +0000 | [diff] [blame] | 1278 | indent-tabs-mode: nil |
Martin v. Löwis | 7d41e29 | 2002-11-23 12:22:32 +0000 | [diff] [blame] | 1279 | End: |
| 1280 | */ |