001: /*
002: *******************************************************************************
003: * Copyright (C) 1998-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: *
007: * Created on Dec 3, 2003
008: *
009: *******************************************************************************
010: */
011: package com.ibm.icu.dev.tool.layout;
012:
013: import com.ibm.icu.lang.UCharacter;
014: import com.ibm.icu.lang.UProperty;
015: import com.ibm.icu.text.Normalizer;
016: import com.ibm.icu.text.UnicodeSet;
017:
018: public class ArabicCharacterData {
019: public class Record {
020: public int getCodePoint() {
021: return codePoint;
022: }
023:
024: public int getGeneralCategory() {
025: return generalCategory;
026: }
027:
028: public int getDecompositionType() {
029: return decompositionType;
030: }
031:
032: public String getDecomposition() {
033: return decomposition;
034: }
035:
036: private Record(int character) {
037: codePoint = character;
038: generalCategory = UCharacter.getType(character);
039: decompositionType = UCharacter.getIntPropertyValue(
040: character, UProperty.DECOMPOSITION_TYPE);
041:
042: switch (decompositionType) {
043: case UCharacter.DecompositionType.FINAL:
044: case UCharacter.DecompositionType.INITIAL:
045: case UCharacter.DecompositionType.ISOLATED:
046: case UCharacter.DecompositionType.MEDIAL:
047: decomposition = Normalizer.compose(UCharacter
048: .toString(character), true);
049: break;
050:
051: case UCharacter.DecompositionType.CANONICAL:
052: decomposition = Normalizer.decompose(UCharacter
053: .toString(character), true);
054: break;
055:
056: default:
057: decomposition = null;
058: }
059: }
060:
061: private int codePoint;
062: private int generalCategory;
063: private int decompositionType;
064: private String decomposition;
065: }
066:
067: private ArabicCharacterData(int charCount) {
068: records = new Record[charCount];
069: }
070:
071: private void add(int character) {
072: records[recordIndex++] = new Record(character);
073: }
074:
075: public Record getRecord(int index) {
076: if (index < 0 || index >= records.length) {
077: return null;
078: }
079:
080: return records[index];
081: }
082:
083: public int countRecords() {
084: return records.length;
085: }
086:
087: // TODO: do we need to change this to use UnicodeSetIterator?
088: // That will mean not knowing the number of characters until
089: // after the iteration is done, so we'd have to use a vector
090: // to hold the Records at first and copy it to an array
091: // when we're done...
092: public static ArabicCharacterData factory(UnicodeSet characterSet) {
093: int charCount = characterSet.size();
094: ArabicCharacterData data = new ArabicCharacterData(charCount);
095:
096: for (int i = 0; i < charCount; i += 1) {
097: data.add(characterSet.charAt(i));
098: }
099:
100: return data;
101: }
102:
103: private Record[] records;
104: private int recordIndex = 0;
105: }
|