KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > CharacterModel


1 /*
2  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * See end of file.
4  */

5
6 package com.hp.hpl.jena.rdf.arp;
7
8 import com.ibm.icu.lang.UCharacter;
9 import com.ibm.icu.text.Normalizer;
10 /**
11  * Some support for the Character Model Recommendation
12  * from the W3C (currently in second last call working
13  * draft).
14  *
15  * @author Jeremy Carroll
16  *
17  *
18  */

19 public class CharacterModel {
20     static private final boolean SWITCH_OFF = false;
21     /** Is this string in Unicode Normal Form C.
22      * @param str The string to be tested.
23      */

24     static public boolean isNormalFormC(String JavaDoc str) {
25         try {
26        return SWITCH_OFF || Normalizer. isNormalized(str,Normalizer.NFC,0);
27         }
28         catch (ArrayIndexOutOfBoundsException JavaDoc e) {
29             // false below means "NFC" see javadoc for compose().
30
String JavaDoc normalized = Normalizer.compose(str,false);
31             return normalized.equals(str);
32         }
33     }
34     
35     /* Does this string start with a composing character as defined
36      * by the
37      * <a HREF="http://www.w3.org/TR/charmod">
38      * Character Model 2nd Last Call Working Draft</a>.
39      * @param str The string to be tested.
40      */

41     static public boolean startsWithComposingCharacter(String JavaDoc str) {
42         return SWITCH_OFF ? false : (str.length()==0?false:isComposingChar(str.charAt(0)));
43     }
44 /** Is this string fully normalized as defined
45      * by the
46      * <a HREF="http://www.w3.org/TR/charmod">
47      * Character Model 2nd Last Call Working Draft</a>.
48      * @param str The string to be tested.
49      */

50     static public boolean isFullyNormalizedConstruct(String JavaDoc str) {
51         return SWITCH_OFF || (isNormalFormC(str) && !startsWithComposingCharacter(str));
52     }
53     /** Is the character a composing character as defined
54      * by the
55      * <a HREF="http://www.w3.org/TR/charmod">
56      * Character Model 2nd Last Call Working Draft</a>.
57      * @param x The character to be tested.
58      */

59    static public boolean isComposingChar(char x) {
60     if ( SWITCH_OFF )
61         return false;
62     switch (x) {
63 // Brahmi-derived scripts
64
case 0X09BE: // BENGALI VOWEL SIGN AA
65
case 0X09D7: // BENGALI AU LENGTH MARK
66
case 0X0B3E: // ORIYA VOWEL SIGN AA
67
case 0X0B56: // ORIYA AI LENGTH MARK
68
case 0X0B57: // ORIYA AU LENGTH MARK
69
case 0X0BBE: // TAMIL VOWEL SIGN AA
70
case 0X0BD7: // TAMIL AU LENGTH MARK
71
case 0X0CC2: // KANNADA VOWEL SIGN UU
72
case 0X0CD5: // KANNADA LENGTH MARK
73
case 0X0CD6: // KANNADA AI LENGTH MARK
74
case 0X0D3E: // MALAYALAM VOWEL SIGN AA
75
case 0X0D57: // MALAYALAM AU LENGTH MARK
76
case 0X0DCF: // SINHALA VOWEL SIGN AELA-PILLA
77
case 0X0DDF: // SINHALA VOWEL SING GAYANUKITTA
78
case 0X0FB5: // TIBETAN SUBJOINED LETTER SSA
79
case 0X0FB7: // TIBETAN SUBJOINED LETTER HA
80
case 0X102E: // MYANMAR VOWEL SIGN II
81
// Hangul vowels
82
case 0X1161: // HANGUL JUNGSEONG A
83
case 0X1162: // HANGUL JUNGSEONG AE
84
case 0X1163: // HANGUL JUNGSEONG YA
85
case 0X1164: // HANGUL JUNGSEONG YAE
86
case 0X1165: // HANGUL JUNGSEONG EO
87
case 0X1166: // HANGUL JUNGSEONG E
88
case 0X1167: // HANGUL JUNGSEONG YEO
89
case 0X1168: // HANGUL JUNGSEONG YE
90
case 0X1169: // HANGUL JUNGSEONG O
91
case 0X116A: // HANGUL JUNGSEONG WA
92
case 0X116B: // HANGUL JUNGSEONG WAE
93
case 0X116C: // HANGUL JUNGSEONG OE
94
case 0X116D: // HANGUL JUNGSEONG YO
95
case 0X116E: // HANGUL JUNGSEONG U
96
case 0X116F: // HANGUL JUNGSEONG WEO
97
case 0X1170: // HANGUL JUNGSEONG WE
98
case 0X1171: // HANGUL JUNGSEONG WI
99
case 0X1172: // HANGUL JUNGSEONG YU
100
case 0X1173: // HANGUL JUNGSEONG EU
101
case 0X1174: // HANGUL JUNGSEONG YI
102
case 0X1175: // HANGUL JUNGSEONG I
103
// Hangul trailing consonants
104
case 0X11A8: // HANGUL JONGSEONG KIYEOK
105
case 0X11A9: // HANGUL JONGSEONG SSANGKIYEOK
106
case 0X11AA: // HANGUL JONGSEONG KIYEOK-SIOS
107
case 0X11AB: // HANGUL JONGSEONG NIEUN
108
case 0X11AC: // HANGUL JONGSEONG NIEUN-CIEUC
109
case 0X11AD: // HANGUL JONGSEONG NIEUN-HIEUH
110
case 0X11AE: // HANGUL JONGSEONG TIKEUT
111
case 0X11AF: // HANGUL JONGSEONG RIEUL
112
case 0X11B0: // HANGUL JONGSEONG RIEUL-KIYEOK
113
case 0X11B1: // HANGUL JONGSEONG RIEUL-MIEUM
114
case 0X11B2: // HANGUL JONGSEONG RIEUL-PIEUP
115
case 0X11B3: // HANGUL JONGSEONG RIEUL-SIOS
116
case 0X11B4: // HANGUL JONGSEONG RIEUL-THIEUTH
117
case 0X11B5: // HANGUL JONGSEONG RIEUL-PHIEUPH
118
case 0X11B6: // HANGUL JONGSEONG RIEUL-HIEUH
119
case 0X11B7: // HANGUL JONGSEONG MIEUM
120
case 0X11B8: // HANGUL JONGSEONG PIEUP
121
case 0X11B9: // HANGUL JONGSEONG PIEUP-SIOS
122
case 0X11BA: // HANGUL JONGSEONG SIOS
123
case 0X11BB: // HANGUL JONGSEONG SSANGSIOS
124
case 0X11BC: // HANGUL JONGSEONG IEUNG
125
case 0X11BD: // HANGUL JONGSEONG CIEUC
126
case 0X11BE: // HANGUL JONGSEONG CHIEUCH
127
case 0X11BF: // HANGUL JONGSEONG KHIEUKH
128
case 0X11C0: // HANGUL JONGSEONG THIEUTH
129
case 0X11C1: // HANGUL JONGSEONG PHIEUPH
130
case 0X11C2: // HANGUL JONGSEONG HIEUH
131
return true;
132    default:
133    return UCharacter.getCombiningClass(x) != 0;
134     }
135    }
136 /*
137    static public void main(String args[]) {
138     int ch = Integer.parseInt(args[0],16);
139     System.out.println(UCharacter.getCombiningClass(ch));
140    }
141  */

142 }
143
144 /*
145  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
146  * All rights reserved.
147  *
148  * Redistribution and use in source and binary forms, with or without
149  * modification, are permitted provided that the following conditions
150  * are met:
151  * 1. Redistributions of source code must retain the above copyright
152  * notice, this list of conditions and the following disclaimer.
153  * 2. Redistributions in binary form must reproduce the above copyright
154  * notice, this list of conditions and the following disclaimer in the
155  * documentation and/or other materials provided with the distribution.
156  * 3. The name of the author may not be used to endorse or promote products
157  * derived from this software without specific prior written permission.
158
159  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
160  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
161  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
162  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
163  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
164  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
165  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
166  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
167  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
168  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
169  */

170
Popular Tags