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