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