Guido van Rossum | 5bfc2eb | 2000-03-10 23:08:04 +0000 | [diff] [blame] | 1 | /* ------------------------------------------------------------------------ |
| 2 | |
| 3 | unicodedatabase -- The Unicode 3.0 data base. |
| 4 | |
| 5 | Data was extracted from the Unicode 3.0 UnicodeData.txt file. |
| 6 | |
Fredrik Lundh | cfcea49 | 2000-09-25 08:07:06 +0000 | [diff] [blame] | 7 | Written by Marc-Andre Lemburg (mal@lemburg.com). |
| 8 | Rewritten for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com) |
Guido van Rossum | 5bfc2eb | 2000-03-10 23:08:04 +0000 | [diff] [blame] | 9 | |
Fredrik Lundh | cfcea49 | 2000-09-25 08:07:06 +0000 | [diff] [blame] | 10 | Copyright (c) Corporation for National Research Initiatives. |
Guido van Rossum | 5bfc2eb | 2000-03-10 23:08:04 +0000 | [diff] [blame] | 11 | |
| 12 | ------------------------------------------------------------------------ */ |
| 13 | |
Marc-André Lemburg | ff50ad5 | 2000-09-30 17:34:31 +0000 | [diff] [blame] | 14 | #include "Python.h" |
Guido van Rossum | 5bfc2eb | 2000-03-10 23:08:04 +0000 | [diff] [blame] | 15 | #include "unicodedatabase.h" |
| 16 | |
Fredrik Lundh | eedb576 | 2000-09-24 21:28:28 +0000 | [diff] [blame] | 17 | /* read the actual data from a separate file! */ |
| 18 | #include "unicodedata_db.h" |
Guido van Rossum | 5bfc2eb | 2000-03-10 23:08:04 +0000 | [diff] [blame] | 19 | |
Fredrik Lundh | eedb576 | 2000-09-24 21:28:28 +0000 | [diff] [blame] | 20 | const _PyUnicode_DatabaseRecord * |
| 21 | _PyUnicode_Database_GetRecord(int code) |
| 22 | { |
| 23 | int index; |
Guido van Rossum | 5bfc2eb | 2000-03-10 23:08:04 +0000 | [diff] [blame] | 24 | |
Fredrik Lundh | eedb576 | 2000-09-24 21:28:28 +0000 | [diff] [blame] | 25 | if (code < 0 || code >= 65536) |
| 26 | index = 0; |
| 27 | else { |
| 28 | index = index1[(code>>SHIFT)]; |
| 29 | index = index2[(index<<SHIFT)+(code&((1<<SHIFT)-1))]; |
| 30 | } |
| 31 | return &_PyUnicode_Database_Records[index]; |
| 32 | } |
Fredrik Lundh | cfcea49 | 2000-09-25 08:07:06 +0000 | [diff] [blame] | 33 | |
| 34 | const char * |
| 35 | _PyUnicode_Database_GetDecomposition(int code) |
| 36 | { |
| 37 | int index; |
| 38 | |
| 39 | if (code < 0 || code >= 65536) |
| 40 | index = 0; |
| 41 | else { |
| 42 | index = decomp_index1[(code>>DECOMP_SHIFT)]; |
| 43 | index = decomp_index2[(index<<DECOMP_SHIFT)+ |
| 44 | (code&((1<<DECOMP_SHIFT)-1))]; |
| 45 | } |
| 46 | return decomp_data[index]; |
| 47 | } |