2005-07-27 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / corlib / Mono.Globalization.Unicode / CollationDataStructures.txt
1 * Collation Data structure and code
2
3
4 ** General
5
6         I will create a code generator named "collation-builder" (currently
7         create-mscompat-collation-table.cs), which creates collation support
8         source files:
9
10         - collation-tables.h : C header that holds raw constant arrays
11         - CollationTable.cs : C# source that declares raw constant arrays
12
13         The latter one is totally optional. It is created just for ease of
14         debugging in pure managed world.
15
16         CollationSource class is used to represent a culture-specific collation
17         resource set.
18
19         Note that there are many characters whose sortkey cannot be acquired
20         only via those tables. For example, Korean Jamo ((U+1113 - U+115F) has
21         primary keys which is more than 2 bytes.
22
23
24 ** Manual tasks required to maintain the source.
25
26         We should always pay attention to the contants for CodePointIndexer
27         that is likely not be in sync with the constant arrays.
28
29
30
31 ** collation-tables.h
32
33         typedef struct {
34                 ushort lcid;
35                 ushort tailoringIndex;
36                 ushort tailoringCount;
37                 short reverseAccentOrder; /* 1:French sort. 0:Normal */
38         } TailoringInfo;
39
40         Those [*] characters will be compressed using CodePointIndexer
41         whose max value is char.MaxValue+1.
42
43         // Holds sortkey basis.
44         guint8 [*] category;
45         guint8 [*] level1;
46         guint8 [*] level2;
47         guint8 [*] level3;
48         guint8 [*] ignorableFlags; // 1:complete, 2:symbol, 3:nonspace
49         gunichar [*] widthCompat;
50
51         // Holds special arrays for CJK order which is culture dependent.
52         guint16 [*] cjkCHS;
53         guint16 [*] cjkCHT;
54         guint16 [*] cjkJA;
55         guint16 [*] cjkKO;
56         guint8 [*] cjkKOlv2;
57         gunichar [whole_tailoring_count] tailorings;
58         CollationSource [culture_count] collationSources;
59
60         "tailorings" table holds the entire contract mappings and expansion
61         mappings for all cultures.
62         Actually it is not only "culture dependent tailorings" but also
63         contains expansions for Invariant culture.
64         CollationSource.tailoringIndex holds the index of "tailorings" array
65         to point where its tailorings begin.
66         Tailorings for the culture is counted by tailoringCount.
67
68         If tailoringIndex is 0 then there is no tailorings for the specific
69         culture (it should still handle invariant tailorings).
70
71 ** CollationSourceUtil.cs
72         static CodePointIndexer Category;
73         static CodePointIndexer Level1;
74         static CodePointIndexer Level2;
75         static CodePointIndexer Level3;
76         static CodePointIndexer Ignorable;
77         static CodePointIndexer WidthCompat;
78         static CodePointIndexer CjkCHS;
79         static CodePointIndexer Cjk;
80
81 ** CollatorSource.cs
82
83         static byte [*] category;
84         static byte [*] level1;
85         static byte [*] level2;
86         static byte [*] level3;
87         static byte [*] ignorableFlags; // 1:complete, 2:symbol, 3:nonspace
88         static char [*] widthCompat;
89         static char [] tailorings;
90         static ushort [] cjkCHS;
91         static ushort [] cjkCHT;
92         static ushort [] cjkJA;
93         static ushort [] cjkKO;
94         static byte [] cjkKOlv2;
95
96         class TailoringInfo // instantiated for each CultureInfo
97         {
98                 // Primary constants
99                 int tailoringIndex;
100                 int tailoringCount;
101                 bool frenchSort;
102
103 /*
104                 // This array is set according to CJK type, and CJK type
105                 // will be hardcoded, being identified from LCID.
106                 ushort [] cjk;
107                 // For Korean, level2 table is specially treated.
108                 byte [] cjkLevel2;
109 */
110         }