]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/tools/misc/src/com/ibm/icu/dev/tool/layout/ArabicCharacterData.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / tools / misc / src / com / ibm / icu / dev / tool / layout / ArabicCharacterData.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 1998-2004, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  *\r
7  * Created on Dec 3, 2003\r
8  *\r
9  *******************************************************************************\r
10  */\r
11 package com.ibm.icu.dev.tool.layout;\r
12 \r
13 import com.ibm.icu.lang.UCharacter;\r
14 import com.ibm.icu.lang.UProperty;\r
15 import com.ibm.icu.text.Normalizer;\r
16 import com.ibm.icu.text.UnicodeSet;\r
17 \r
18 public class ArabicCharacterData\r
19 {\r
20     public class Record\r
21     {\r
22         public int getCodePoint()\r
23         {\r
24             return codePoint;\r
25         }\r
26         \r
27         public int getGeneralCategory()\r
28         {\r
29             return generalCategory;\r
30         }\r
31         \r
32         public int getDecompositionType()\r
33         {\r
34             return decompositionType;\r
35         }\r
36         \r
37         public String getDecomposition()\r
38         {\r
39             return decomposition;\r
40         }\r
41         \r
42         private Record(int character)\r
43         {\r
44             codePoint         = character;\r
45             generalCategory   = UCharacter.getType(character);\r
46             decompositionType = UCharacter.getIntPropertyValue(character, UProperty.DECOMPOSITION_TYPE);\r
47             \r
48             switch (decompositionType) {\r
49             case UCharacter.DecompositionType.FINAL:\r
50             case UCharacter.DecompositionType.INITIAL:\r
51             case UCharacter.DecompositionType.ISOLATED:\r
52             case UCharacter.DecompositionType.MEDIAL:\r
53                 decomposition = Normalizer.compose(UCharacter.toString(character), true);\r
54                 break;\r
55                 \r
56             case UCharacter.DecompositionType.CANONICAL:\r
57                 decomposition = Normalizer.decompose(UCharacter.toString(character), true);\r
58                 break;\r
59                 \r
60             default:\r
61                 decomposition = null;\r
62             }\r
63         }\r
64         \r
65         private int codePoint;\r
66         private int generalCategory;\r
67         private int decompositionType;\r
68         private String decomposition;\r
69     }\r
70     \r
71     private ArabicCharacterData(int charCount)\r
72     {\r
73         records = new Record[charCount];\r
74     }\r
75     \r
76     private void add(int character)\r
77     {\r
78         records[recordIndex++] = new Record(character);\r
79     }\r
80     \r
81     public Record getRecord(int index)\r
82     {\r
83         if (index < 0 || index >= records.length) {\r
84             return null;\r
85         }\r
86         \r
87         return records[index];\r
88     }\r
89     \r
90     public int countRecords()\r
91     {\r
92         return records.length;\r
93     }\r
94  \r
95     // TODO: do we need to change this to use UnicodeSetIterator?\r
96     // That will mean not knowing the number of characters until\r
97     // after the iteration is done, so we'd have to use a vector\r
98     // to hold the Records at first and copy it to an array\r
99     // when we're done...   \r
100     public static ArabicCharacterData factory(UnicodeSet characterSet)\r
101     {\r
102         int charCount = characterSet.size();\r
103         ArabicCharacterData data = new ArabicCharacterData(charCount);\r
104         \r
105         for (int i = 0; i < charCount; i += 1) {\r
106             data.add(characterSet.charAt(i));\r
107         }\r
108         \r
109         return data;\r
110     }\r
111     \r
112     private Record[] records;\r
113     private int recordIndex = 0;\r
114 }\r