1 57 58 package com.sun.org.apache.xerces.internal.util; 59 60 import java.util.Arrays ; 61 62 83 public class XML11Char { 84 85 89 90 private static final byte XML11CHARS [] = new byte [1 << 16]; 91 92 93 public static final int MASK_XML11_VALID = 0x01; 94 95 96 public static final int MASK_XML11_SPACE = 0x02; 97 98 99 public static final int MASK_XML11_NAME_START = 0x04; 100 101 102 public static final int MASK_XML11_NAME = 0x08; 103 104 105 public static final int MASK_XML11_CONTROL = 0x10; 106 107 108 public static final int MASK_XML11_CONTENT = 0x20; 109 110 111 public static final int MASK_XML11_NCNAME_START = 0x40; 112 113 114 public static final int MASK_XML11_NCNAME = 0x80; 115 116 117 public static final int MASK_XML11_CONTENT_INTERNAL = MASK_XML11_CONTROL | MASK_XML11_CONTENT; 118 119 123 static { 124 125 128 Arrays.fill(XML11CHARS, 1, 9, (byte) 17 ); XML11CHARS[9] = 35; 130 XML11CHARS[10] = 3; 131 Arrays.fill(XML11CHARS, 11, 13, (byte) 17 ); XML11CHARS[13] = 3; 133 Arrays.fill(XML11CHARS, 14, 32, (byte) 17 ); XML11CHARS[32] = 35; 135 Arrays.fill(XML11CHARS, 33, 38, (byte) 33 ); XML11CHARS[38] = 1; 137 Arrays.fill(XML11CHARS, 39, 45, (byte) 33 ); Arrays.fill(XML11CHARS, 45, 47, (byte) -87 ); XML11CHARS[47] = 33; 140 Arrays.fill(XML11CHARS, 48, 58, (byte) -87 ); XML11CHARS[58] = 45; 142 XML11CHARS[59] = 33; 143 XML11CHARS[60] = 1; 144 Arrays.fill(XML11CHARS, 61, 65, (byte) 33 ); Arrays.fill(XML11CHARS, 65, 91, (byte) -19 ); Arrays.fill(XML11CHARS, 91, 93, (byte) 33 ); XML11CHARS[93] = 1; 148 XML11CHARS[94] = 33; 149 XML11CHARS[95] = -19; 150 XML11CHARS[96] = 33; 151 Arrays.fill(XML11CHARS, 97, 123, (byte) -19 ); Arrays.fill(XML11CHARS, 123, 127, (byte) 33 ); Arrays.fill(XML11CHARS, 127, 133, (byte) 17 ); XML11CHARS[133] = 35; 155 Arrays.fill(XML11CHARS, 134, 160, (byte) 17 ); Arrays.fill(XML11CHARS, 160, 183, (byte) 33 ); XML11CHARS[183] = -87; 158 Arrays.fill(XML11CHARS, 184, 192, (byte) 33 ); Arrays.fill(XML11CHARS, 192, 215, (byte) -19 ); XML11CHARS[215] = 33; 161 Arrays.fill(XML11CHARS, 216, 247, (byte) -19 ); XML11CHARS[247] = 33; 163 Arrays.fill(XML11CHARS, 248, 768, (byte) -19 ); Arrays.fill(XML11CHARS, 768, 880, (byte) -87 ); Arrays.fill(XML11CHARS, 880, 894, (byte) -19 ); XML11CHARS[894] = 33; 167 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; 172 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 ); 185 } 187 191 197 public static boolean isXML11Space(int c) { 198 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_SPACE) != 0); 199 } 201 211 public static boolean isXML11Valid(int c) { 212 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_VALID) != 0) 213 || (0x10000 <= c && c <= 0x10FFFF); 214 } 216 221 public static boolean isXML11Invalid(int c) { 222 return !isXML11Valid(c); 223 } 225 233 public static boolean isXML11ValidLiteral(int c) { 234 return ((c < 0x10000 && ((XML11CHARS[c] & MASK_XML11_VALID) != 0 && (XML11CHARS[c] & MASK_XML11_CONTROL) == 0)) 235 || (0x10000 <= c && c <= 0x10FFFF)); 236 } 238 244 public static boolean isXML11Content(int c) { 245 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_CONTENT) != 0) || 246 (0x10000 <= c && c <= 0x10FFFF); 247 } 249 255 public static boolean isXML11InternalEntityContent(int c) { 256 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_CONTENT_INTERNAL) != 0) || 257 (0x10000 <= c && c <= 0x10FFFF); 258 } 260 267 public static boolean isXML11NameStart(int c) { 268 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NAME_START) != 0) 269 || (0x10000 <= c && c < 0xF0000); 270 } 272 279 public static boolean isXML11Name(int c) { 280 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NAME) != 0) 281 || (c >= 0x10000 && c < 0xF0000); 282 } 284 291 public static boolean isXML11NCNameStart(int c) { 292 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NCNAME_START) != 0) 293 || (0x10000 <= c && c < 0xF0000); 294 } 296 303 public static boolean isXML11NCName(int c) { 304 return (c < 0x10000 && (XML11CHARS[c] & MASK_XML11_NCNAME) != 0) 305 || (0x10000 <= c && c < 0xF0000); 306 } 308 316 public static boolean isXML11NameHighSurrogate(int c) { 317 return (0xD800 <= c && c <= 0xDB7F); 318 } 319 320 323 330 public static boolean isXML11ValidName(String name) { 331 int length = name.length(); 332 if (length == 0) 333 return false; 334 int i = 1; 335 char ch = name.charAt(0); 336 if( !isXML11NameStart(ch) ) { 337 if ( length > 1 && isXML11NameHighSurrogate(ch) ) { 338 char ch2 = name.charAt(1); 339 if ( !XMLChar.isLowSurrogate(ch2) || 340 !isXML11NameStart(XMLChar.supplemental(ch, ch2)) ) { 341 return false; 342 } 343 i = 2; 344 } 345 else { 346 return false; 347 } 348 } 349 while (i < length) { 350 ch = name.charAt(i); 351 if ( !isXML11Name(ch) ) { 352 if ( ++i < length && isXML11NameHighSurrogate(ch) ) { 353 char ch2 = name.charAt(i); 354 if ( !XMLChar.isLowSurrogate(ch2) || 355 !isXML11Name(XMLChar.supplemental(ch, ch2)) ) { 356 return false; 357 } 358 } 359 else { 360 return false; 361 } 362 } 363 ++i; 364 } 365 return true; 366 } 368 369 373 380 public static boolean isXML11ValidNCName(String ncName) { 381 int length = ncName.length(); 382 if (length == 0) 383 return false; 384 int i = 1; 385 char ch = ncName.charAt(0); 386 if( !isXML11NCNameStart(ch) ) { 387 if ( length > 1 && isXML11NameHighSurrogate(ch) ) { 388 char ch2 = ncName.charAt(1); 389 if ( !XMLChar.isLowSurrogate(ch2) || 390 !isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) { 391 return false; 392 } 393 i = 2; 394 } 395 else { 396 return false; 397 } 398 } 399 while (i < length) { 400 ch = ncName.charAt(i); 401 if ( !isXML11NCName(ch) ) { 402 if ( ++i < length && isXML11NameHighSurrogate(ch) ) { 403 char ch2 = ncName.charAt(i); 404 if ( !XMLChar.isLowSurrogate(ch2) || 405 !isXML11NCName(XMLChar.supplemental(ch, ch2)) ) { 406 return false; 407 } 408 } 409 else { 410 return false; 411 } 412 } 413 ++i; 414 } 415 return true; 416 } 418 421 428 public static boolean isXML11ValidNmtoken(String nmtoken) { 429 int length = nmtoken.length(); 430 if (length == 0) 431 return false; 432 for (int i = 0; i < length; ++i ) { 433 char ch = nmtoken.charAt(i); 434 if( !isXML11Name(ch) ) { 435 if ( ++i < length && isXML11NameHighSurrogate(ch) ) { 436 char ch2 = nmtoken.charAt(i); 437 if ( !XMLChar.isLowSurrogate(ch2) || 438 !isXML11Name(XMLChar.supplemental(ch, ch2)) ) { 439 return false; 440 } 441 } 442 else { 443 return false; 444 } 445 } 446 } 447 return true; 448 } 450 } 452 | Popular Tags |