| 1 |
// Borrowed from Apache so that we can use an XMLWriter without using Xerces |
| 2 |
/* |
| 3 |
* The Apache Software License, Version 1.1 |
| 4 |
* |
| 5 |
* |
| 6 |
* Copyright (c) 1999 The Apache Software Foundation. All rights |
| 7 |
* reserved. |
| 8 |
* |
| 9 |
* Redistribution and use in source and binary forms, with or without |
| 10 |
* modification, are permitted provided that the following conditions |
| 11 |
* are met: |
| 12 |
* |
| 13 |
* 1. Redistributions of source code must retain the above copyright |
| 14 |
* notice, this list of conditions and the following disclaimer. |
| 15 |
* |
| 16 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 17 |
* notice, this list of conditions and the following disclaimer in |
| 18 |
* the documentation and/or other materials provided with the |
| 19 |
* distribution. |
| 20 |
* |
| 21 |
* 3. The end-user documentation included with the redistribution, |
| 22 |
* if any, must include the following acknowledgment: |
| 23 |
* "This product includes software developed by the |
| 24 |
* Apache Software Foundation (http://www.apache.org/)." |
| 25 |
* Alternately, this acknowledgment may appear in the software itself, |
| 26 |
* if and wherever such third-party acknowledgments normally appear. |
| 27 |
* |
| 28 |
* 4. The names "Xerces" and "Apache Software Foundation" must |
| 29 |
* not be used to endorse or promote products derived from this |
| 30 |
* software without prior written permission. For written |
| 31 |
* permission, please contact [email protected]. |
| 32 |
* |
| 33 |
* 5. Products derived from this software may not be called "Apache", |
| 34 |
* nor may "Apache" appear in their name, without prior written |
| 35 |
* permission of the Apache Software Foundation. |
| 36 |
* |
| 37 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 38 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 39 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 40 |
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR |
| 41 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 42 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 43 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 44 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 45 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 46 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 47 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 48 |
* SUCH DAMAGE. |
| 49 |
* ==================================================================== |
| 50 |
* |
| 51 |
* This software consists of voluntary contributions made by many |
| 52 |
* individuals on behalf of the Apache Software Foundation and was |
| 53 |
* originally based on software copyright (c) 1999, International |
| 54 |
* Business Machines, Inc., http://www.apache.org. For more |
| 55 |
* information on the Apache Software Foundation, please see |
| 56 |
* <http://www.apache.org/>. |
| 57 |
*/ |
| 58 |
package org.freehep.graphicsbase.xml.util; |
| 59 |
|
| 60 |
// package org.apache.xerces.utils; |
| 61 |
|
| 62 |
/** |
| 63 |
* A class representing properties of characters according to various |
| 64 |
* W3C recommendations |
| 65 |
* |
| 66 |
* XMLCharacterProperties provides convenience methods for commonly used |
| 67 |
* character tests. |
| 68 |
* |
| 69 |
* For performance reasons, the tables used by the convenience methods are |
| 70 |
* also public, and are directly accessed by performance critical routines. |
| 71 |
* |
| 72 |
*/ |
| 73 |
|
| 74 |
public final class XMLCharacterProperties { |
| 75 |
/* |
| 76 |
* [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+ |
| 77 |
* |
| 78 |
* Note: This is the same as the ascii portion of the |
| 79 |
* NameChar definition. |
| 80 |
*/ |
| 81 |
/** |
| 82 |
* Check to see if a string is a valid version string according to |
| 83 |
* [26] in the XML 1.0 Recommendation |
| 84 |
* |
| 85 |
* @param version string to check |
| 86 |
* @return true if version is a valid version string |
| 87 |
*/ |
| 88 |
public static boolean validVersionNum(String version) { |
| 89 |
int len = version.length(); |
| 90 |
if (len == 0) |
| 91 |
return false; |
| 92 |
for (int i = 0; i < len; i++) { |
| 93 |
char ch = version.charAt(i); |
| 94 |
if (ch > 'z' || fgAsciiNameChar[ch] == 0) |
| 95 |
return false; |
| 96 |
} |
| 97 |
return true; |
| 98 |
} |
| 99 |
/* |
| 100 |
* [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* |
| 101 |
*/ |
| 102 |
/** |
| 103 |
* Check to see if a string is a valid encoding name according to [81] |
| 104 |
* in the XML 1.0 Recommendation |
| 105 |
* |
| 106 |
* @param encoding string to check |
| 107 |
* @return true if encoding is a valid encoding name |
| 108 |
*/ |
| 109 |
public static boolean validEncName(String encoding) { |
| 110 |
int len = encoding.length(); |
| 111 |
if (len == 0) |
| 112 |
return false; |
| 113 |
char ch = encoding.charAt(0); |
| 114 |
if (ch > 'z' || fgAsciiAlphaChar[ch] == 0) |
| 115 |
return false; |
| 116 |
for (int i = 1; i < len; i++) { |
| 117 |
ch = encoding.charAt(i); |
| 118 |
if (ch > 'z' || fgAsciiEncNameChar[ch] == 0) |
| 119 |
return false; |
| 120 |
} |
| 121 |
return true; |
| 122 |
} |
| 123 |
/* |
| 124 |
* [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] |
| 125 |
*/ |
| 126 |
/** |
| 127 |
* Check to see if a string is a valid public identifier according to [13] |
| 128 |
* in the XML 1.0 Recommendation |
| 129 |
* |
| 130 |
* @param publicId string to check |
| 131 |
* @return true if publicId is a valid public identifier |
| 132 |
*/ |
| 133 |
public static int validPublicId(String publicId) { |
| 134 |
int len = publicId.length(); |
| 135 |
if (len == 0) |
| 136 |
return -1; |
| 137 |
for (int i = 0; i < len; i++) { |
| 138 |
char ch = publicId.charAt(i); |
| 139 |
if (ch > 'z' || fgAsciiPubidChar[ch] == 0) |
| 140 |
return i; |
| 141 |
} |
| 142 |
return -1; |
| 143 |
} |
| 144 |
/* |
| 145 |
* [5] Name ::= (Letter | '_' | ':') (NameChar)* |
| 146 |
*/ |
| 147 |
/** |
| 148 |
* Check to see if a string is a valid Name according to [5] |
| 149 |
* in the XML 1.0 Recommendation |
| 150 |
* |
| 151 |
* @param name string to check |
| 152 |
* @return true if name is a valid Name |
| 153 |
*/ |
| 154 |
public static boolean validName(String name) { |
| 155 |
int len = name.length(); |
| 156 |
if (len == 0) |
| 157 |
return false; |
| 158 |
char ch = name.charAt(0); |
| 159 |
if (ch > 'z') { |
| 160 |
if ((fgCharFlags[ch] & E_InitialNameCharFlag) == 0) |
| 161 |
return false; |
| 162 |
} else if (fgAsciiInitialNameChar[ch] == 0) |
| 163 |
return false; |
| 164 |
for (int i = 1; i < len; i++) { |
| 165 |
ch = name.charAt(i); |
| 166 |
if (ch > 'z') { |
| 167 |
if ((fgCharFlags[ch] & E_NameCharFlag) == 0) |
| 168 |
return false; |
| 169 |
} else if (fgAsciiNameChar[ch] == 0) |
| 170 |
return false; |
| 171 |
} |
| 172 |
return true; |
| 173 |
} |
| 174 |
|
| 175 |
/* |
| 176 |
* from the namespace rec |
| 177 |
* [4] NCName ::= (Letter | '_') (NCNameChar)* |
| 178 |
*/ |
| 179 |
/** |
| 180 |
* Check to see if a string is a valid NCName according to [4] |
| 181 |
* from the XML Namespaces 1.0 Recommendation |
| 182 |
* |
| 183 |
* @param name string to check |
| 184 |
* @return true if name is a valid NCName |
| 185 |
*/ |
| 186 |
public static boolean validNCName(String name) { |
| 187 |
int len = name.length(); |
| 188 |
if (len == 0) |
| 189 |
return false; |
| 190 |
char ch = name.charAt(0); |
| 191 |
if (ch > 'z') { |
| 192 |
if ((fgCharFlags[ch] & E_InitialNameCharFlag) == 0) |
| 193 |
return false; |
| 194 |
} else if (fgAsciiInitialNCNameChar[ch] == 0) |
| 195 |
return false; |
| 196 |
for (int i = 1; i < len; i++) { |
| 197 |
ch = name.charAt(i); |
| 198 |
if (ch > 'z') { |
| 199 |
if ((fgCharFlags[ch] & E_NameCharFlag) == 0) |
| 200 |
return false; |
| 201 |
} else if (fgAsciiNCNameChar[ch] == 0) |
| 202 |
return false; |
| 203 |
} |
| 204 |
return true; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
/* |
| 209 |
* [7] Nmtoken ::= (NameChar)+ |
| 210 |
*/ |
| 211 |
/** |
| 212 |
* Check to see if a string is a valid Nmtoken according to [7] |
| 213 |
* in the XML 1.0 Recommendation |
| 214 |
* |
| 215 |
* @param nmtoken string to checj |
| 216 |
* @return true if nmtoken is a valid Nmtoken |
| 217 |
*/ |
| 218 |
public static boolean validNmtoken(String nmtoken) { |
| 219 |
int len = nmtoken.length(); |
| 220 |
if (len == 0) |
| 221 |
return false; |
| 222 |
for (int i = 0; i < len; i++) { |
| 223 |
char ch = nmtoken.charAt(i); |
| 224 |
if (ch > 'z') { |
| 225 |
if ((fgCharFlags[ch] & E_NameCharFlag) == 0) |
| 226 |
return false; |
| 227 |
} else if (fgAsciiNameChar[ch] == 0) { |
| 228 |
return false; |
| 229 |
} |
| 230 |
} |
| 231 |
return true; |
| 232 |
} |
| 233 |
/* |
| 234 |
* Here are tables used to build character properties. |
| 235 |
*/ |
| 236 |
public static final byte fgAsciiXDigitChar[] = { |
| 237 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 238 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 239 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 240 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // '0' - '9' |
| 241 |
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 'A' - 'F' |
| 242 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 243 |
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 'a' - 'f' |
| 244 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 245 |
}; |
| 246 |
public static final byte fgAsciiAlphaChar[] = { |
| 247 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 248 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 249 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 250 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 251 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'A' - 'O' |
| 252 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 'P' - 'Z' |
| 253 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a' - 'o' |
| 254 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 'p' - 'z' |
| 255 |
}; |
| 256 |
public static final byte fgAsciiEncNameChar[] = { |
| 257 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 258 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 259 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, // '-' is 0x2D and '.' is 0x2E |
| 260 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // '0' - '9' |
| 261 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'A' - 'O' |
| 262 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 'P' - 'Z' and '_' is 0x5F |
| 263 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a' - 'o' |
| 264 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 'p' - 'z' |
| 265 |
}; |
| 266 |
public static final byte fgAsciiPubidChar[] = { |
| 267 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, |
| 268 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 269 |
1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, // ' ', '!', '#', '$', '%', |
| 270 |
// '\'', '(', ')', '*', '+', ',', '-', '.', '/' |
| 271 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, // '0' - '9', ':', ';', '=', '?' |
| 272 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // '@', 'A' - 'O' |
| 273 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 'P' - 'Z' and '_' is 0x5F |
| 274 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a' - 'o' |
| 275 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 'p' - 'z' |
| 276 |
}; |
| 277 |
public static final byte fgAsciiInitialNameChar[] = { |
| 278 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 279 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 280 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 281 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, // ':' is 0x3A |
| 282 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'A' - 'O' |
| 283 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 'P' - 'Z' and '_' is 0x5F |
| 284 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a' - 'o' |
| 285 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 'p' - 'z' |
| 286 |
}; |
| 287 |
public static final byte fgAsciiNameChar[] = { |
| 288 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 289 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 290 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, // '-' is 0x2D and '.' is 0x2E |
| 291 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // '0' - '9' and ':' is 0x3A |
| 292 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'A' - 'O' |
| 293 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 'P' - 'Z' and '_' is 0x5F |
| 294 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a' - 'o' |
| 295 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 'p' - 'z' |
| 296 |
}; |
| 297 |
public static final byte fgAsciiInitialNCNameChar[] = { |
| 298 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 299 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 300 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 301 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ':' is 0x3A |
| 302 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'A' - 'O' |
| 303 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 'P' - 'Z' and '_' is 0x5F |
| 304 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a' - 'o' |
| 305 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 'p' - 'z' |
| 306 |
}; |
| 307 |
public static final byte fgAsciiNCNameChar[] = { |
| 308 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 309 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 310 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, // '-' is 0x2D and '.' is 0x2E |
| 311 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // '0' - '9' and ':' is 0x3A |
| 312 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'A' - 'O' |
| 313 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 'P' - 'Z' and '_' is 0x5F |
| 314 |
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a' - 'o' |
| 315 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 // 'p' - 'z' |
| 316 |
}; |
| 317 |
public static final byte fgAsciiCharData[] = { |
| 318 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, // tab is 0x09 |
| 319 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
| 320 |
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, // '&' is 0x26 |
| 321 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, // '<' is 0x3C |
| 322 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 323 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, // ']' is 0x5D |
| 324 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 325 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 326 |
}; |
| 327 |
public static final byte fgAsciiWSCharData[] = { |
| 328 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 5, 4, 4, // tab is 0x09, LF is 0x0A, CR is 0x0D |
| 329 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
| 330 |
5, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ' ' is 0x20, '&' is 0x26 |
| 331 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, // '<' is 0x3C |
| 332 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 333 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, // ']' is 0x5D |
| 334 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 335 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 336 |
}; |
| 337 |
public static final byte E_CharDataFlag = 1<<0; |
| 338 |
public static final byte E_InitialNameCharFlag = 1<<1; |
| 339 |
public static final byte E_NameCharFlag = 1<<2; |
| 340 |
public static byte[] fgCharFlags = null; |
| 341 |
public static synchronized void initCharFlags() { |
| 342 |
if (fgCharFlags == null) { |
| 343 |
fgCharFlags = new byte[0x10000]; |
| 344 |
setFlagForRange(fgCharDataRanges, E_CharDataFlag); |
| 345 |
setFlagForRange(fgInitialNameCharRanges, (byte)(E_InitialNameCharFlag | E_NameCharFlag)); |
| 346 |
setFlagForRange(fgNameCharRanges, E_NameCharFlag); |
| 347 |
} |
| 348 |
} |
| 349 |
private static void setFlagForRange(char[] ranges, byte flag) |
| 350 |
{ |
| 351 |
int i; |
| 352 |
int ch; |
| 353 |
for (i = 0; (ch = ranges[i]) != 0; i += 2) { |
| 354 |
int endch = ranges[i+1]; |
| 355 |
while (ch <= endch) |
| 356 |
fgCharFlags[ch++] |= flag; |
| 357 |
} |
| 358 |
for (i++; (ch = ranges[i]) != 0; i++) |
| 359 |
fgCharFlags[ch] |= flag; |
| 360 |
} |
| 361 |
/* |
| 362 |
* [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] // any Unicode character, excluding the |
| 363 |
* | [#xE000-#xFFFD] | [#x10000-#x10FFFF] // surrogate blocks, FFFE, and FFFF. |
| 364 |
* [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) |
| 365 |
* |
| 366 |
* We will use Char - ( [^<&] | ']' | #xA | #xD ) and handle the special cases inline. |
| 367 |
*/ |
| 368 |
private static final char fgCharDataRanges[] = { |
| 369 |
0x0020, 0x0025, // '&' is 0x0026 |
| 370 |
0x0027, 0x003B, // '<' is 0x003C |
| 371 |
0x003D, 0x005C, // ']' is 0x005D |
| 372 |
0x005E, 0xD7FF, |
| 373 |
0xE000, 0xFFFD, |
| 374 |
0x0000, |
| 375 |
0x0009, // tab |
| 376 |
0x0000 |
| 377 |
}; |
| 378 |
/* |
| 379 |
* [5] Name ::= (Letter | '_' | ':') (NameChar)* |
| 380 |
* [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender |
| 381 |
* [84] Letter ::= BaseChar | Ideographic |
| 382 |
* [85] BaseChar ::= <see standard> |
| 383 |
* [86] Ideographic ::= <see standard> |
| 384 |
* [87] CombiningChar ::= <see standard> |
| 385 |
* [88] Digit ::= <see standard> |
| 386 |
* [89] Extender ::= <see standard> |
| 387 |
*/ |
| 388 |
private static final char fgInitialNameCharRanges[] = { |
| 389 |
// |
| 390 |
// Ranges: |
| 391 |
// |
| 392 |
// BaseChar ranges |
| 393 |
// |
| 394 |
0x0041, 0x005A, 0x0061, 0x007A, 0x00C0, 0x00D6, 0x00D8, 0x00F6, |
| 395 |
0x00F8, 0x0131, 0x0134, 0x013E, 0x0141, 0x0148, 0x014A, 0x017E, |
| 396 |
0x0180, 0x01C3, 0x01CD, 0x01F0, 0x01F4, 0x01F5, 0x01FA, 0x0217, |
| 397 |
0x0250, 0x02A8, 0x02BB, 0x02C1, 0x0388, 0x038A, 0x038E, 0x03A1, |
| 398 |
0x03A3, 0x03CE, 0x03D0, 0x03D6, 0x03E2, 0x03F3, 0x0401, 0x040C, |
| 399 |
0x040E, 0x044F, 0x0451, 0x045C, 0x045E, 0x0481, 0x0490, 0x04C4, |
| 400 |
0x04C7, 0x04C8, 0x04CB, 0x04CC, 0x04D0, 0x04EB, 0x04EE, 0x04F5, |
| 401 |
0x04F8, 0x04F9, 0x0531, 0x0556, 0x0561, 0x0586, 0x05D0, 0x05EA, |
| 402 |
0x05F0, 0x05F2, 0x0621, 0x063A, 0x0641, 0x064A, 0x0671, 0x06B7, |
| 403 |
0x06BA, 0x06BE, 0x06C0, 0x06CE, 0x06D0, 0x06D3, 0x06E5, 0x06E6, |
| 404 |
0x0905, 0x0939, 0x0958, 0x0961, 0x0985, 0x098C, 0x098F, 0x0990, |
| 405 |
0x0993, 0x09A8, 0x09AA, 0x09B0, 0x09B6, 0x09B9, 0x09DC, 0x09DD, |
| 406 |
0x09DF, 0x09E1, 0x09F0, 0x09F1, 0x0A05, 0x0A0A, 0x0A0F, 0x0A10, |
| 407 |
0x0A13, 0x0A28, 0x0A2A, 0x0A30, 0x0A32, 0x0A33, 0x0A35, 0x0A36, |
| 408 |
0x0A38, 0x0A39, 0x0A59, 0x0A5C, 0x0A72, 0x0A74, 0x0A85, 0x0A8B, |
| 409 |
0x0A8F, 0x0A91, 0x0A93, 0x0AA8, 0x0AAA, 0x0AB0, 0x0AB2, 0x0AB3, |
| 410 |
0x0AB5, 0x0AB9, 0x0B05, 0x0B0C, 0x0B0F, 0x0B10, 0x0B13, 0x0B28, |
| 411 |
0x0B2A, 0x0B30, 0x0B32, 0x0B33, 0x0B36, 0x0B39, 0x0B5C, 0x0B5D, |
| 412 |
0x0B5F, 0x0B61, 0x0B85, 0x0B8A, 0x0B8E, 0x0B90, 0x0B92, 0x0B95, |
| 413 |
0x0B99, 0x0B9A, 0x0B9E, 0x0B9F, 0x0BA3, 0x0BA4, 0x0BA8, 0x0BAA, |
| 414 |
0x0BAE, 0x0BB5, 0x0BB7, 0x0BB9, 0x0C05, 0x0C0C, 0x0C0E, 0x0C10, |
| 415 |
0x0C12, 0x0C28, 0x0C2A, 0x0C33, 0x0C35, 0x0C39, 0x0C60, 0x0C61, |
| 416 |
0x0C85, 0x0C8C, 0x0C8E, 0x0C90, 0x0C92, 0x0CA8, 0x0CAA, 0x0CB3, |
| 417 |
0x0CB5, 0x0CB9, 0x0CE0, 0x0CE1, 0x0D05, 0x0D0C, 0x0D0E, 0x0D10, |
| 418 |
0x0D12, 0x0D28, 0x0D2A, 0x0D39, 0x0D60, 0x0D61, 0x0E01, 0x0E2E, |
| 419 |
0x0E32, 0x0E33, 0x0E40, 0x0E45, 0x0E81, 0x0E82, 0x0E87, 0x0E88, |
| 420 |
0x0E94, 0x0E97, 0x0E99, 0x0E9F, 0x0EA1, 0x0EA3, 0x0EAA, 0x0EAB, |
| 421 |
0x0EAD, 0x0EAE, 0x0EB2, 0x0EB3, 0x0EC0, 0x0EC4, 0x0F40, 0x0F47, |
| 422 |
0x0F49, 0x0F69, 0x10A0, 0x10C5, 0x10D0, 0x10F6, 0x1102, 0x1103, |
| 423 |
0x1105, 0x1107, 0x110B, 0x110C, 0x110E, 0x1112, 0x1154, 0x1155, |
| 424 |
0x115F, 0x1161, 0x116D, 0x116E, 0x1172, 0x1173, 0x11AE, 0x11AF, |
| 425 |
0x11B7, 0x11B8, 0x11BC, 0x11C2, 0x1E00, 0x1E9B, 0x1EA0, 0x1EF9, |
| 426 |
0x1F00, 0x1F15, 0x1F18, 0x1F1D, 0x1F20, 0x1F45, 0x1F48, 0x1F4D, |
| 427 |
0x1F50, 0x1F57, 0x1F5F, 0x1F7D, 0x1F80, 0x1FB4, 0x1FB6, 0x1FBC, |
| 428 |
0x1FC2, 0x1FC4, 0x1FC6, 0x1FCC, 0x1FD0, 0x1FD3, 0x1FD6, 0x1FDB, |
| 429 |
0x1FE0, 0x1FEC, 0x1FF2, 0x1FF4, 0x1FF6, 0x1FFC, 0x212A, 0x212B, |
| 430 |
0x2180, 0x2182, 0x3041, 0x3094, 0x30A1, 0x30FA, 0x3105, 0x312C, |
| 431 |
0xAC00, 0xD7A3, |
| 432 |
// |
| 433 |
// Ideographic ranges |
| 434 |
// |
| 435 |
0x3021, 0x3029, 0x4E00, 0x9FA5, |
| 436 |
// |
| 437 |
// Ranges end marker |
| 438 |
// |
| 439 |
0x0000, |
| 440 |
// |
| 441 |
// Single char values |
| 442 |
// |
| 443 |
0x003A, // ':' |
| 444 |
0x005F, // '_' |
| 445 |
// |
| 446 |
// BaseChar singles |
| 447 |
// |
| 448 |
0x0386, 0x038C, 0x03DA, 0x03DC, 0x03DE, 0x03E0, 0x0559, 0x06D5, |
| 449 |
0x093D, 0x09B2, 0x0A5E, 0x0A8D, 0x0ABD, 0x0AE0, 0x0B3D, 0x0B9C, |
| 450 |
0x0CDE, 0x0E30, 0x0E84, 0x0E8A, 0x0E8D, 0x0EA5, 0x0EA7, 0x0EB0, |
| 451 |
0x0EBD, 0x1100, 0x1109, 0x113C, 0x113E, 0x1140, 0x114C, 0x114E, |
| 452 |
0x1150, 0x1159, 0x1163, 0x1165, 0x1167, 0x1169, 0x1175, 0x119E, |
| 453 |
0x11A8, 0x11AB, 0x11BA, 0x11EB, 0x11F0, 0x11F9, 0x1F59, 0x1F5B, |
| 454 |
0x1F5D, 0x1FBE, 0x2126, 0x212E, |
| 455 |
// |
| 456 |
// Ideographic singles |
| 457 |
// |
| 458 |
0x3007, |
| 459 |
// |
| 460 |
// Singles end marker |
| 461 |
// |
| 462 |
0x0000 |
| 463 |
}; |
| 464 |
private static final char fgNameCharRanges[] = { |
| 465 |
// |
| 466 |
// Ranges: |
| 467 |
// |
| 468 |
0x002D, 0x002E, // '-' and '.' |
| 469 |
// |
| 470 |
// CombiningChar ranges |
| 471 |
// |
| 472 |
0x0300, 0x0345, 0x0360, 0x0361, 0x0483, 0x0486, 0x0591, 0x05A1, |
| 473 |
0x05A3, 0x05B9, 0x05BB, 0x05BD, 0x05C1, 0x05C2, 0x064B, 0x0652, |
| 474 |
0x06D6, 0x06DC, 0x06DD, 0x06DF, 0x06E0, 0x06E4, 0x06E7, 0x06E8, |
| 475 |
0x06EA, 0x06ED, 0x0901, 0x0903, 0x093E, 0x094C, 0x0951, 0x0954, |
| 476 |
0x0962, 0x0963, 0x0981, 0x0983, 0x09C0, 0x09C4, 0x09C7, 0x09C8, |
| 477 |
0x09CB, 0x09CD, 0x09E2, 0x09E3, 0x0A40, 0x0A42, 0x0A47, 0x0A48, |
| 478 |
0x0A4B, 0x0A4D, 0x0A70, 0x0A71, 0x0A81, 0x0A83, 0x0ABE, 0x0AC5, |
| 479 |
0x0AC7, 0x0AC9, 0x0ACB, 0x0ACD, 0x0B01, 0x0B03, 0x0B3E, 0x0B43, |
| 480 |
0x0B47, 0x0B48, 0x0B4B, 0x0B4D, 0x0B56, 0x0B57, 0x0B82, 0x0B83, |
| 481 |
0x0BBE, 0x0BC2, 0x0BC6, 0x0BC8, 0x0BCA, 0x0BCD, 0x0C01, 0x0C03, |
| 482 |
0x0C3E, 0x0C44, 0x0C46, 0x0C48, 0x0C4A, 0x0C4D, 0x0C55, 0x0C56, |
| 483 |
0x0C82, 0x0C83, 0x0CBE, 0x0CC4, 0x0CC6, 0x0CC8, 0x0CCA, 0x0CCD, |
| 484 |
0x0CD5, 0x0CD6, 0x0D02, 0x0D03, 0x0D3E, 0x0D43, 0x0D46, 0x0D48, |
| 485 |
0x0D4A, 0x0D4D, 0x0E34, 0x0E3A, 0x0E47, 0x0E4E, 0x0EB4, 0x0EB9, |
| 486 |
0x0EBB, 0x0EBC, 0x0EC8, 0x0ECD, 0x0F18, 0x0F19, 0x0F71, 0x0F84, |
| 487 |
0x0F86, 0x0F8B, 0x0F90, 0x0F95, 0x0F99, 0x0FAD, 0x0FB1, 0x0FB7, |
| 488 |
0x20D0, 0x20DC, 0x302A, 0x302F, |
| 489 |
// |
| 490 |
// Digit ranges |
| 491 |
// |
| 492 |
0x0030, 0x0039, 0x0660, 0x0669, 0x06F0, 0x06F9, 0x0966, 0x096F, |
| 493 |
0x09E6, 0x09EF, 0x0A66, 0x0A6F, 0x0AE6, 0x0AEF, 0x0B66, 0x0B6F, |
| 494 |
0x0BE7, 0x0BEF, 0x0C66, 0x0C6F, 0x0CE6, 0x0CEF, 0x0D66, 0x0D6F, |
| 495 |
0x0E50, 0x0E59, 0x0ED0, 0x0ED9, 0x0F20, 0x0F29, |
| 496 |
// |
| 497 |
// Extender ranges |
| 498 |
// |
| 499 |
0x3031, 0x3035, 0x309D, 0x309E, 0x30FC, 0x30FE, |
| 500 |
// |
| 501 |
// Ranges end marker |
| 502 |
// |
| 503 |
0x0000, |
| 504 |
// |
| 505 |
// Single char values |
| 506 |
// |
| 507 |
// CombiningChar singles |
| 508 |
// |
| 509 |
0x05BF, 0x05C4, 0x0670, 0x093C, 0x094D, 0x09BC, 0x09BE, 0x09BF, |
| 510 |
0x09D7, 0x0A02, 0x0A3C, 0x0A3E, 0x0A3F, 0x0ABC, 0x0B3C, 0x0BD7, |
| 511 |
0x0D57, 0x0E31, 0x0EB1, 0x0F35, 0x0F37, 0x0F39, 0x0F3E, 0x0F3F, |
| 512 |
0x0F97, 0x0FB9, 0x20E1, 0x3099, 0x309A, |
| 513 |
// |
| 514 |
// Extender singles |
| 515 |
// |
| 516 |
0x00B7, 0x02D0, 0x02D1, 0x0387, 0x0640, 0x0E46, 0x0EC6, 0x3005, |
| 517 |
// |
| 518 |
// Singles end marker |
| 519 |
// |
| 520 |
0x0000 |
| 521 |
}; |
| 522 |
} |