1 16 17 package org.apache.xerces.util; 18 19 import java.util.Arrays ; 20 21 42 public class XML11Char { 43 44 48 49 private static final byte XML11CHARS [] = new byte [1 << 16]; 50 51 52 public static final int MASK_XML11_VALID = 0x01; 53 54 55 public static final int MASK_XML11_SPACE = 0x02; 56 57 58 public static final int MASK_XML11_NAME_START = 0x04; 59 60 61 public static final int MASK_XML11_NAME = 0x08; 62 63 64 public static final int MASK_XML11_CONTROL = 0x10; 65 66 67 public static final int MASK_XML11_CONTENT = 0x20; 68 69 70 public static final int MASK_XML11_NCNAME_START = 0x40; 71 72 73 public static final int MASK_XML11_NCNAME = 0x80; 74 75 76 public static final int MASK_XML11_CONTENT_INTERNAL = MASK_XML11_CONTROL | MASK_XML11_CONTENT; 77 78 82 static { 83 84 87 Arrays.fill(XML11CHARS, 1, 9, (byte) 17 ); XML11CHARS[9] = 35; 89 XML11CHARS[10] = 3; 90 Arrays.fill(XML11CHARS, 11, 13, (byte) 17 ); XML11CHARS[13] = 3; 92 Arrays.fill(XML11CHARS, 14, 32, (byte) 17 ); XML11CHARS[32] = 35; 94 Arrays.fill(XML11CHARS, 33, 38, (byte) 33 ); XML11CHARS[38] = 1; 96 Arrays.fill(XML11CHARS, 39, 45, (byte) 33 ); Arrays.fill(XML11CHARS, 45, 47, (byte) -87 ); XML11CHARS[47] = 33; 99 Arrays.fill(XML11CHARS, 48, 58, (byte) -87 ); XML11CHARS[58] = 45; 101 XML11CHARS[59] = 33; 102 XML11CHARS[60] = 1; 103 Arrays.fill(XML11CHARS, 61, 65, (byte) 33 ); Arrays.fill(XML11CHARS, 65, 91, (byte) -19 ); Arrays.fill(XML11CHARS, 91, 93, (byte) 33 ); XML11CHARS[93] = 1; 107 XML11CHARS[94] = 33; 108 XML11CHARS[95] = -19; 109 XML11CHARS[96] = 33; 110 Arrays.fill(XML11CHARS, 97, 123, (byte) -19 ); Arrays.fill(XML11CHARS, 123, 127, (byte) 33 ); Arrays.fill(XML11CHARS, 127, 133, (byte) 17 ); XML11CHARS[133] = 35; 114 Arrays.fill(XML11CHARS, 134, 160, (byte) 17 ); Arrays.fill(XML11CHARS, 160, 183, (byte) 33 ); XML11CHARS[183] = -87; 117 Arrays.fill(XML11CHARS, 184, 192, (byte) 33 ); Arrays.fill(XML11CHARS, 192, 215, (byte) -19 ); XML11CHARS[215] = 33; 120 Arrays.fill(XML11CHARS, 216, 247, (byte) -19 ); XML11CHARS[247] = 33; 122 Arrays.fill(XML11CHARS, 248, 768, (byte) -19 ); Arrays.fill(XML11CHARS, 768, 880, (byte) -87 ); Arrays.fill(XML11CHARS, 880, 894, (byte) -19 ); XML11CHARS[894] = 33; 126 Arrays.fill(XML11CHARS, 895, 8192, (byte) -19 ); Arrays.fill(XML11CHARS, 8192, 8204, (byte) 33 ); Arrays.fill(XML11CHARS, 8204, 8206, (byte) -19 ); Arrays.fill(XML11CHARS, 8206, 8232, (byte) 33 ); XML11CHARS[8232] = 35; 131 Arrays.fill(XML11CHARS, 8233, 8255, (byte) 33 ); Arrays.fill(XML11CHARS, 8255, 8257, (byte) -87 ); Arrays.fill(XML11CHARS, 8257, 8304, (byte) 33 ); Arrays.fill(XML11CHARS, 8304, 8592, (byte) -19 ); Arrays.fill(XML11CHARS, 8592, 11264, (byte) 33 ); Arrays.fill(XML11CHARS, 11264, 12272, (byte) -19 ); Arrays.fill(XML11CHARS, 12272, 12289, (byte) 33 ); Arrays.fill(XML11CHARS, 12289, 55296, (byte) -19 ); Arrays.fill(XML11CHARS, 57344, 63744, (byte) 33 ); Arrays.fill(XML11CHARS, 63744, 64976, (byte) -19 ); Arrays.fill(XML11CHARS, 64976, 65008, (byte) 33 ); Arrays.fill(XML11CHARS, 65008, 65534, (byte) -19 ); 144 } 146 150 156 public static boolean isXML11Space(int c) { 157 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_SPACE) != 0); 158 } 160 170 public static boolean isXML11Valid(int c) { 171 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_VALID) != 0) 172 || (0x10000 <= c && c <= 0x10FFFF); 173 } 175 180 public static boolean isXML11Invalid(int c) { 181 return !isXML11Valid(c); 182 } 184 192 public static boolean isXML11ValidLiteral(int c) { 193 return ((c < 0x10000 && ((XML11CHARS[c] & MASK_XML11_VALID) != 0 && (XML11CHARS[c] & MASK_XML11_CONTROL) == 0)) 194 || (0x10000 <= c && c <= 0x10FFFF)); 195 } 197 203 public static boolean isXML11Content(int c) { 204 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_CONTENT) != 0) || 205 (0x10000 <= c && c <= 0x10FFFF); 206 } 208 214 public static boolean isXML11InternalEntityContent(int c) { 215 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_CONTENT_INTERNAL) != 0) || 216 (0x10000 <= c && c <= 0x10FFFF); 217 } 219 226 public static boolean isXML11NameStart(int c) { 227 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NAME_START) != 0) 228 || (0x10000 <= c && c < 0xF0000); 229 } 231 238 public static boolean isXML11Name(int c) { 239 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NAME) != 0) 240 || (c >= 0x10000 && c < 0xF0000); 241 } 243 250 public static boolean isXML11NCNameStart(int c) { 251 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NCNAME_START) != 0) 252 || (0x10000 <= c && c < 0xF0000); 253 } 255 262 public static boolean isXML11NCName(int c) { 263 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NCNAME) != 0) 264 || (0x10000 <= c && c < 0xF0000); 265 } 267 275 public static boolean isXML11NameHighSurrogate(int c) { 276 return (0xD800 <= c && c <= 0xDB7F); 277 } 278 279 282 289 public static boolean isXML11ValidName(String name) { 290 int length = name.length(); 291 if (length == 0) 292 return false; 293 int i = 1; 294 char ch = name.charAt(0); 295 if( !isXML11NameStart(ch) ) { 296 if ( length > 1 && isXML11NameHighSurrogate(ch) ) { 297 char ch2 = name.charAt(1); 298 if ( !XMLChar.isLowSurrogate(ch2) || 299 !isXML11NameStart(XMLChar.supplemental(ch, ch2)) ) { 300 return false; 301 } 302 i = 2; 303 } 304 else { 305 return false; 306 } 307 } 308 while (i < length) { 309 ch = name.charAt(i); 310 if ( !isXML11Name(ch) ) { 311 if ( ++i < length && isXML11NameHighSurrogate(ch) ) { 312 char ch2 = name.charAt(i); 313 if ( !XMLChar.isLowSurrogate(ch2) || 314 !isXML11Name(XMLChar.supplemental(ch, ch2)) ) { 315 return false; 316 } 317 } 318 else { 319 return false; 320 } 321 } 322 ++i; 323 } 324 return true; 325 } 327 328 332 339 public static boolean isXML11ValidNCName(String ncName) { 340 int length = ncName.length(); 341 if (length == 0) 342 return false; 343 int i = 1; 344 char ch = ncName.charAt(0); 345 if( !isXML11NCNameStart(ch) ) { 346 if ( length > 1 && isXML11NameHighSurrogate(ch) ) { 347 char ch2 = ncName.charAt(1); 348 if ( !XMLChar.isLowSurrogate(ch2) || 349 !isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) { 350 return false; 351 } 352 i = 2; 353 } 354 else { 355 return false; 356 } 357 } 358 while (i < length) { 359 ch = ncName.charAt(i); 360 if ( !isXML11NCName(ch) ) { 361 if ( ++i < length && isXML11NameHighSurrogate(ch) ) { 362 char ch2 = ncName.charAt(i); 363 if ( !XMLChar.isLowSurrogate(ch2) || 364 !isXML11NCName(XMLChar.supplemental(ch, ch2)) ) { 365 return false; 366 } 367 } 368 else { 369 return false; 370 } 371 } 372 ++i; 373 } 374 return true; 375 } 377 380 387 public static boolean isXML11ValidNmtoken(String nmtoken) { 388 int length = nmtoken.length(); 389 if (length == 0) 390 return false; 391 for (int i = 0; i < length; ++i ) { 392 char ch = nmtoken.charAt(i); 393 if( !isXML11Name(ch) ) { 394 if ( ++i < length && isXML11NameHighSurrogate(ch) ) { 395 char ch2 = nmtoken.charAt(i); 396 if ( !XMLChar.isLowSurrogate(ch2) || 397 !isXML11Name(XMLChar.supplemental(ch, ch2)) ) { 398 return false; 399 } 400 } 401 else { 402 return false; 403 } 404 } 405 } 406 return true; 407 } 409 } 411 | Popular Tags |