Determining validity of characters outside basic 7-bit range of Unicode, for XML 1.0 : XMLEncoder « XML « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » XML » XMLEncoderScreenshots 
Determining validity of characters outside basic 7-bit range of Unicode, for XML 1.0
    
// Revised from ctc wstx

/**
 * Simple utility class that encapsulates logic of determining validity
 * of characters outside basic 7-bit range of Unicode, for XML 1.0
 */
public final class XmlChars
{
    /* We don't need full 64k bits... (0x80 - 0x312C) / 32. But to
     * simplify things, let's just include first 0x80 entries in there etc
     */
    final static int SIZE = (0x3140 >> 5)// 32 bits per int

    final static int[] sXml10StartChars = new int[SIZE];
    static {
        SETBITS(sXml10StartChars, 0xC00xD6);
        SETBITS(sXml10StartChars, 0xD80xF6);
        SETBITS(sXml10StartChars, 0xF80xFF);
        SETBITS(sXml10StartChars, 0x1000x131);
        SETBITS(sXml10StartChars, 0x1340x13e);
        SETBITS(sXml10StartChars, 0x1410x148);
        SETBITS(sXml10StartChars, 0x14a0x17e);
        SETBITS(sXml10StartChars, 0x1800x1c3);
        SETBITS(sXml10StartChars, 0x1cd0x1f0);
        SETBITS(sXml10StartChars, 0x1f40x1f5);
        SETBITS(sXml10StartChars, 0x1fa0x217);
        SETBITS(sXml10StartChars, 0x2500x2a8);
        SETBITS(sXml10StartChars, 0x2bb0x2c1);
        SETBITS(sXml10StartChars, 0x386);
        SETBITS(sXml10StartChars, 0x3880x38a);
        SETBITS(sXml10StartChars, 0x38c);
        SETBITS(sXml10StartChars, 0x38e0x3a1);
        SETBITS(sXml10StartChars, 0x3a30x3ce);
        SETBITS(sXml10StartChars, 0x3d00x3d6);
        SETBITS(sXml10StartChars, 0x3da);
        SETBITS(sXml10StartChars, 0x3dc);
        SETBITS(sXml10StartChars, 0x3de);
        SETBITS(sXml10StartChars, 0x3e0);
        SETBITS(sXml10StartChars, 0x3e20x3f3);
        SETBITS(sXml10StartChars, 0x4010x40c);
        SETBITS(sXml10StartChars, 0x40e0x44f);
        SETBITS(sXml10StartChars, 0x4510x45c);
        SETBITS(sXml10StartChars, 0x45e0x481);
        SETBITS(sXml10StartChars, 0x4900x4c4);
        SETBITS(sXml10StartChars, 0x4c70x4c8);
        SETBITS(sXml10StartChars, 0x4cb0x4cc);
        SETBITS(sXml10StartChars, 0x4d00x4eb);
        SETBITS(sXml10StartChars, 0x4ee0x4f5);
        SETBITS(sXml10StartChars, 0x4f80x4f9);

        SETBITS(sXml10StartChars, 0x5310x556);
        SETBITS(sXml10StartChars, 0x559);
        SETBITS(sXml10StartChars, 0x5610x586);
        SETBITS(sXml10StartChars, 0x5d00x5ea);
        SETBITS(sXml10StartChars, 0x5f00x5f2);
        SETBITS(sXml10StartChars, 0x6210x63a);
        SETBITS(sXml10StartChars, 0x6410x64a);
        SETBITS(sXml10StartChars, 0x6710x6b7);
        SETBITS(sXml10StartChars, 0x6ba0x6be);
        SETBITS(sXml10StartChars, 0x6c00x6ce);
        SETBITS(sXml10StartChars, 0x6d00x6d3);
        SETBITS(sXml10StartChars, 0x6d5);

        SETBITS(sXml10StartChars, 0x6e50x6e6);
        SETBITS(sXml10StartChars, 0x9050x939);
        SETBITS(sXml10StartChars, 0x93d);
        SETBITS(sXml10StartChars, 0x9580x961);
        SETBITS(sXml10StartChars, 0x9850x98c);
        SETBITS(sXml10StartChars, 0x98f0x990);
        SETBITS(sXml10StartChars, 0x9930x9a8);
        SETBITS(sXml10StartChars, 0x9aa0x9b0);
        SETBITS(sXml10StartChars, 0x9b2);
        SETBITS(sXml10StartChars, 0x9b60x9b9);
        SETBITS(sXml10StartChars, 0x9dc);
        SETBITS(sXml10StartChars, 0x9dd);
        SETBITS(sXml10StartChars, 0x9df0x9e1);
        SETBITS(sXml10StartChars, 0x9f0); SETBITS(sXml10StartChars, 0x9f1);
        SETBITS(sXml10StartChars, 0xA050xA0A);
        SETBITS(sXml10StartChars, 0xA0F); SETBITS(sXml10StartChars, 0xA10);
        SETBITS(sXml10StartChars, 0xA130xA28);
        SETBITS(sXml10StartChars, 0xA2A0xA30);
        SETBITS(sXml10StartChars, 0xA32); SETBITS(sXml10StartChars, 0xA33);
        SETBITS(sXml10StartChars, 0xA35); SETBITS(sXml10StartChars, 0xA36);
        SETBITS(sXml10StartChars, 0xA38); SETBITS(sXml10StartChars, 0xA39);
        SETBITS(sXml10StartChars, 0xA590xA5C);
        SETBITS(sXml10StartChars, 0xA5E);
        SETBITS(sXml10StartChars, 0xA720xA74);
        SETBITS(sXml10StartChars, 0xA850xA8B);
        SETBITS(sXml10StartChars, 0xA8D);
        SETBITS(sXml10StartChars, 0xA8F0xA91);
        SETBITS(sXml10StartChars, 0xA930xAA8);
        SETBITS(sXml10StartChars, 0xAAA0xAB0);
        SETBITS(sXml10StartChars, 0xAB20xAB3);
        SETBITS(sXml10StartChars, 0xAB50xAB9);
        SETBITS(sXml10StartChars, 0xABD);
        SETBITS(sXml10StartChars, 0xAE0);
        SETBITS(sXml10StartChars, 0xB050xB0C);
        SETBITS(sXml10StartChars, 0xB0F); SETBITS(sXml10StartChars, 0xB10);
        SETBITS(sXml10StartChars, 0xB130xB28);

        SETBITS(sXml10StartChars, 0xB2A0xB30);
        SETBITS(sXml10StartChars, 0xB32); SETBITS(sXml10StartChars, 0xB33);
        SETBITS(sXml10StartChars, 0xB360xB39);
        SETBITS(sXml10StartChars, 0xB3D);
        SETBITS(sXml10StartChars, 0xB5C); SETBITS(sXml10StartChars, 0xB5D);
        SETBITS(sXml10StartChars, 0xB5F0xB61);
        SETBITS(sXml10StartChars, 0xB850xB8A);
        SETBITS(sXml10StartChars, 0xB8E0xB90);

        SETBITS(sXml10StartChars, 0xB920xB95);
        SETBITS(sXml10StartChars, 0xB990xB9A);
        SETBITS(sXml10StartChars, 0xB9C);
        SETBITS(sXml10StartChars, 0xB9E); SETBITS(sXml10StartChars, 0xB9F);
        SETBITS(sXml10StartChars, 0xBA3); SETBITS(sXml10StartChars, 0xBA4);
        SETBITS(sXml10StartChars, 0xBA80xBAA);
        SETBITS(sXml10StartChars, 0xBAE0xBB5);
        SETBITS(sXml10StartChars, 0xBB70xBB9);
        SETBITS(sXml10StartChars, 0xC050xC0C);
        SETBITS(sXml10StartChars, 0xC0E0xC10);

        SETBITS(sXml10StartChars, 0xC120xC28);
        SETBITS(sXml10StartChars, 0xC2A0xC33);
        SETBITS(sXml10StartChars, 0xC350xC39);
        SETBITS(sXml10StartChars, 0xC60); SETBITS(sXml10StartChars, 0xC61);
        SETBITS(sXml10StartChars, 0xC850xC8C);
        SETBITS(sXml10StartChars, 0xC8E0xC90);
        SETBITS(sXml10StartChars, 0xC920xCA8);
        SETBITS(sXml10StartChars, 0xCAA0xCB3);
        SETBITS(sXml10StartChars, 0xCB50xCB9);
        SETBITS(sXml10StartChars, 0xCDE);
        SETBITS(sXml10StartChars, 0xCE0); SETBITS(sXml10StartChars, 0xCE1);
        SETBITS(sXml10StartChars, 0xD050xD0C);
        SETBITS(sXml10StartChars, 0xD0E0xD10);
        SETBITS(sXml10StartChars, 0xD120xD28);
        SETBITS(sXml10StartChars, 0xD2A0xD39);
        SETBITS(sXml10StartChars, 0xD60); SETBITS(sXml10StartChars, 0xD61);
        SETBITS(sXml10StartChars, 0xE010xE2E);
        SETBITS(sXml10StartChars, 0xE30);
        SETBITS(sXml10StartChars, 0xE32); SETBITS(sXml10StartChars, 0xE33);
        SETBITS(sXml10StartChars, 0xE400xE45);
        SETBITS(sXml10StartChars, 0xE81); SETBITS(sXml10StartChars, 0xE82);
        SETBITS(sXml10StartChars, 0xE84);
        SETBITS(sXml10StartChars, 0xE87); SETBITS(sXml10StartChars, 0xE88);
        SETBITS(sXml10StartChars, 0xE8A); SETBITS(sXml10StartChars, 0xE8D);
        SETBITS(sXml10StartChars, 0xE940xE97);
        SETBITS(sXml10StartChars, 0xE990xE9F);
        SETBITS(sXml10StartChars, 0xEA10xEA3);
        SETBITS(sXml10StartChars, 0xEA5); SETBITS(sXml10StartChars, 0xEA7);
        SETBITS(sXml10StartChars, 0xEAA); SETBITS(sXml10StartChars, 0xEAB);
        SETBITS(sXml10StartChars, 0xEAD); SETBITS(sXml10StartChars, 0xEAE);
        SETBITS(sXml10StartChars, 0xEB0);
        SETBITS(sXml10StartChars, 0xEB2); SETBITS(sXml10StartChars, 0xEB3);
        SETBITS(sXml10StartChars, 0xEBD);

        SETBITS(sXml10StartChars, 0xEC00xEC4);
        SETBITS(sXml10StartChars, 0xF400xF47);
        SETBITS(sXml10StartChars, 0xF490xF69);
        SETBITS(sXml10StartChars, 0x10a00x10c5);
        SETBITS(sXml10StartChars, 0x10d00x10f6);
        SETBITS(sXml10StartChars, 0x1100);
        SETBITS(sXml10StartChars, 0x11020x1103);
        SETBITS(sXml10StartChars, 0x11050x1107);
        SETBITS(sXml10StartChars, 0x1109);
        SETBITS(sXml10StartChars, 0x110b0x110c);
        SETBITS(sXml10StartChars, 0x110e0x1112);
        SETBITS(sXml10StartChars, 0x113c);
        SETBITS(sXml10StartChars, 0x113e);
        SETBITS(sXml10StartChars, 0x1140);
        SETBITS(sXml10StartChars, 0x114c);
        SETBITS(sXml10StartChars, 0x114e);
        SETBITS(sXml10StartChars, 0x1150);
        SETBITS(sXml10StartChars, 0x11540x1155);
        SETBITS(sXml10StartChars, 0x1159);
        SETBITS(sXml10StartChars, 0x115f0x1161);
        SETBITS(sXml10StartChars, 0x1163);
        SETBITS(sXml10StartChars, 0x1165);
        SETBITS(sXml10StartChars, 0x1167);
        SETBITS(sXml10StartChars, 0x1169);
        SETBITS(sXml10StartChars, 0x116d0x116e);
        SETBITS(sXml10StartChars, 0x11720x1173);
        SETBITS(sXml10StartChars, 0x1175);
        SETBITS(sXml10StartChars, 0x119e);
        SETBITS(sXml10StartChars, 0x11a8);
        SETBITS(sXml10StartChars, 0x11ab);
        SETBITS(sXml10StartChars, 0x11ae0x11af);
        SETBITS(sXml10StartChars, 0x11b70x11b8);
        SETBITS(sXml10StartChars, 0x11ba);
        SETBITS(sXml10StartChars, 0x11bc0x11c2);
        SETBITS(sXml10StartChars, 0x11eb);
        SETBITS(sXml10StartChars, 0x11f0);
        SETBITS(sXml10StartChars, 0x11f9);
        SETBITS(sXml10StartChars, 0x1e000x1e9b);
        SETBITS(sXml10StartChars, 0x1ea00x1ef9);
        SETBITS(sXml10StartChars, 0x1f000x1f15);
        SETBITS(sXml10StartChars, 0x1f180x1f1d);
        SETBITS(sXml10StartChars, 0x1f200x1f45);
        SETBITS(sXml10StartChars, 0x1f480x1f4d);
        SETBITS(sXml10StartChars, 0x1f500x1f57);
        SETBITS(sXml10StartChars, 0x1f59);
        SETBITS(sXml10StartChars, 0x1f5b);
        SETBITS(sXml10StartChars, 0x1f5d);
        SETBITS(sXml10StartChars, 0x1f5f0x1f7d);
        SETBITS(sXml10StartChars, 0x1f800x1fb4);
        SETBITS(sXml10StartChars, 0x1fb60x1fbc);
        SETBITS(sXml10StartChars, 0x1fbe);
        SETBITS(sXml10StartChars, 0x1fc20x1fc4);
        SETBITS(sXml10StartChars, 0x1fc60x1fcc);
        SETBITS(sXml10StartChars, 0x1fd00x1fd3);
        SETBITS(sXml10StartChars, 0x1fd60x1fdb);
        SETBITS(sXml10StartChars, 0x1fe00x1fec);
        SETBITS(sXml10StartChars, 0x1ff20x1ff4);
        SETBITS(sXml10StartChars, 0x1ff60x1ffc);
        SETBITS(sXml10StartChars, 0x2126);
        SETBITS(sXml10StartChars, 0x212a0x212b);
        SETBITS(sXml10StartChars, 0x212e);
        SETBITS(sXml10StartChars, 0x21800x2182);
        SETBITS(sXml10StartChars, 0x30410x3094);
        SETBITS(sXml10StartChars, 0x30a10x30fa);
        SETBITS(sXml10StartChars, 0x31050x312c);
        // note: AC00 - D7A3 handled separately

        // [86] Ideographic (but note: > 0x312c handled separately)
        SETBITS(sXml10StartChars, 0x3007);
        SETBITS(sXml10StartChars, 0x30210x3029);
    }

    final static int[] sXml10Chars = new int[SIZE];
    static {
        // Let's start with all valid start chars:
        System.arraycopy(sXml10StartChars, 0, sXml10Chars, 0, SIZE);

        // [87] CombiningChar    ::=
        SETBITS(sXml10Chars, 0x3000x345);
        SETBITS(sXml10Chars, 0x3600x361);
        SETBITS(sXml10Chars, 0x4830x486);
        SETBITS(sXml10Chars, 0x5910x5a1);
        SETBITS(sXml10Chars, 0x5a30x5b9);
        SETBITS(sXml10Chars, 0x5bb0x5bd);
        SETBITS(sXml10Chars, 0x5bf);

        SETBITS(sXml10Chars, 0x5c10x5c2);
        SETBITS(sXml10Chars, 0x5c4);
        SETBITS(sXml10Chars, 0x64b0x652);
        SETBITS(sXml10Chars, 0x670);
        SETBITS(sXml10Chars, 0x6d60x6dc);
        SETBITS(sXml10Chars, 0x6dd0x6df);
        SETBITS(sXml10Chars, 0x6e00x6e4);
        SETBITS(sXml10Chars, 0x6e70x6e8);
        SETBITS(sXml10Chars, 0x6ea0x6ed);

        SETBITS(sXml10Chars, 0x9010x903);
        SETBITS(sXml10Chars, 0x93c);
        SETBITS(sXml10Chars, 0x93e0x94c);
        SETBITS(sXml10Chars, 0x94d);
        SETBITS(sXml10Chars, 0x9510x954);
        SETBITS(sXml10Chars, 0x962); SETBITS(sXml10Chars, 0x963);
        SETBITS(sXml10Chars, 0x9810x983);
        SETBITS(sXml10Chars, 0x9bc);
        SETBITS(sXml10Chars, 0x9be); SETBITS(sXml10Chars, 0x9bf);
        SETBITS(sXml10Chars, 0x9c00x9c4);
        SETBITS(sXml10Chars, 0x9c7); SETBITS(sXml10Chars, 0x9c8);
        SETBITS(sXml10Chars, 0x9cb0x9cd);
        SETBITS(sXml10Chars, 0x9d7);
        SETBITS(sXml10Chars, 0x9e2); SETBITS(sXml10Chars, 0x9e3);
        SETBITS(sXml10Chars, 0xA02);
        SETBITS(sXml10Chars, 0xA3C);
        SETBITS(sXml10Chars, 0xA3E); SETBITS(sXml10Chars, 0xA3F);
        SETBITS(sXml10Chars, 0xA400xA42);
        SETBITS(sXml10Chars, 0xA47); SETBITS(sXml10Chars, 0xA48);
        SETBITS(sXml10Chars, 0xA4B0xA4D);
        SETBITS(sXml10Chars, 0xA70); SETBITS(sXml10Chars, 0xA71);
        SETBITS(sXml10Chars, 0xA810xA83);
        SETBITS(sXml10Chars, 0xABC);
        SETBITS(sXml10Chars, 0xABE0xAC5);
        SETBITS(sXml10Chars, 0xAC70xAC9);
        SETBITS(sXml10Chars, 0xACB0xACD);
        SETBITS(sXml10Chars, 0xB010xB03);
        SETBITS(sXml10Chars, 0xB3C);
        SETBITS(sXml10Chars, 0xB3E0xB43);
        SETBITS(sXml10Chars, 0xB47); SETBITS(sXml10Chars, 0xB48);
        SETBITS(sXml10Chars, 0xB4B0xB4D);
        SETBITS(sXml10Chars, 0xB56); SETBITS(sXml10Chars, 0xB57);
        SETBITS(sXml10Chars, 0xB82); SETBITS(sXml10Chars, 0xB83);
        SETBITS(sXml10Chars, 0xBBE0xBC2);
        SETBITS(sXml10Chars, 0xBC60xBC8);
        SETBITS(sXml10Chars, 0xBCA0xBCD);
        SETBITS(sXml10Chars, 0xBD7);
        SETBITS(sXml10Chars, 0xC010xC03);
        SETBITS(sXml10Chars, 0xC3E0xC44);
        SETBITS(sXml10Chars, 0xC460xC48);
        SETBITS(sXml10Chars, 0xC4A0xC4D);
        SETBITS(sXml10Chars, 0xC550xC56);
        SETBITS(sXml10Chars, 0xC820xC83);
        SETBITS(sXml10Chars, 0xCBE0xCC4);
        SETBITS(sXml10Chars, 0xCC60xCC8);
        SETBITS(sXml10Chars, 0xCCA0xCCD);
        SETBITS(sXml10Chars, 0xCD50xCD6);
        SETBITS(sXml10Chars, 0xD020xD03);
        SETBITS(sXml10Chars, 0xD3E0xD43);
        SETBITS(sXml10Chars, 0xD460xD48);
        SETBITS(sXml10Chars, 0xD4A0xD4D);
        SETBITS(sXml10Chars, 0xD57);
        SETBITS(sXml10Chars, 0xE31);
        SETBITS(sXml10Chars, 0xE340xE3A);
        SETBITS(sXml10Chars, 0xE470xE4E);
        SETBITS(sXml10Chars, 0xEB1);
        SETBITS(sXml10Chars, 0xEB40xEB9);
        SETBITS(sXml10Chars, 0xEBB0xEBC);
        SETBITS(sXml10Chars, 0xEC80xECD);
        SETBITS(sXml10Chars, 0xF180xF19);
        SETBITS(sXml10Chars, 0xF35); SETBITS(sXml10Chars, 0xF37);
        SETBITS(sXml10Chars, 0xF39);
        SETBITS(sXml10Chars, 0xF3E); SETBITS(sXml10Chars, 0xF3F);
        SETBITS(sXml10Chars, 0xF710xF84);
        SETBITS(sXml10Chars, 0xF860xF8B);
        SETBITS(sXml10Chars, 0xF900xF95);
        SETBITS(sXml10Chars, 0xF97);
        SETBITS(sXml10Chars, 0xF990xFAD);
        SETBITS(sXml10Chars, 0xFB10xFB7);
        SETBITS(sXml10Chars, 0xFB9);
        SETBITS(sXml10Chars, 0x20D00x20DC);
        SETBITS(sXml10Chars, 0x20E1);
        SETBITS(sXml10Chars, 0x302A0x302F);
        SETBITS(sXml10Chars, 0x3099); SETBITS(sXml10Chars, 0x309A);
        // [88] Digit:
        SETBITS(sXml10Chars, 0x6600x669);
        SETBITS(sXml10Chars, 0x6f00x6f9);
        SETBITS(sXml10Chars, 0x9660x96f);
        SETBITS(sXml10Chars, 0x9e60x9ef);
        SETBITS(sXml10Chars, 0xa660xa6f);
        SETBITS(sXml10Chars, 0xae60xaef);
        SETBITS(sXml10Chars, 0xb660xb6f);
        SETBITS(sXml10Chars, 0xbe70xbef);
        SETBITS(sXml10Chars, 0xc660xc6f);
        SETBITS(sXml10Chars, 0xce60xcef);
        SETBITS(sXml10Chars, 0xd660xd6f);
        SETBITS(sXml10Chars, 0xe500xe59);
        SETBITS(sXml10Chars, 0xed00xed9);
        SETBITS(sXml10Chars, 0xf200xf29);
        
        // [89] Extender:
        SETBITS(sXml10Chars, 0xb7);
        SETBITS(sXml10Chars, 0x2d0);
        SETBITS(sXml10Chars, 0x2d1);
        SETBITS(sXml10Chars, 0x387);
        SETBITS(sXml10Chars, 0x640);
        SETBITS(sXml10Chars, 0xE46);
        SETBITS(sXml10Chars, 0xEC6);
        SETBITS(sXml10Chars, 0x3005);
        SETBITS(sXml10Chars, 0x30310x3035);
        SETBITS(sXml10Chars, 0x309d0x309e);
        SETBITS(sXml10Chars, 0x30fc0x30fe);
    }
    
    private XmlChars() { }

    public final static boolean is10NameStartChar(char c)
    {
        // First, let's deal with outliers
        if (c > 0x312C) { // Most valid chars are below this..
            if (c < 0xAC00) {
                return (c >= 0x4E00 && c <= 0x9FA5)// valid ideograms
            }
            if (c <= 0xD7A3) { // 0xAC00 - 0xD7A3, valid base chars
                return true;
            }
            /* As to surrogate pairs... let's do the bare minimum;
             * 0xD800 - 0xDBFF (high surrogate) are ok; low surrogates
             * can only follow high one
             */
            return (c <= 0xDBFF && c >= 0xD800);
        }
        // but then we'll just need to use the table...
        int ix = (intc;
        return (sXml10StartChars[ix >> 5(<< (ix & 31))) != 0;
    }

    public final static boolean is10NameChar(char c)
    {
        // First, let's deal with outliers
        if (c > 0x312C) { // Most valid chars are below this..
            if (c < 0xAC00) {
                return (c >= 0x4E00 && c <= 0x9FA5)// valid ideograms
            }
            if (c <= 0xD7A3) { // 0xAC00 - 0xD7A3, valid base chars
                return true;
            }
            /* As to surrogate pairs... let's do the bare minimum;
             * 0xD800 - 0xDFFF (high, low surrogate) are ok (need to
             * check pairing in future)
             */
            return (c >= 0xD800 && c <= 0xDFFF);
        }
        // but then we'll just need to use the table...
        int ix = (intc;
        return (sXml10Chars[ix >> 5(<< (ix & 31))) != 0;
    }

    public final static boolean is11NameStartChar(char c)
    {
        // Others are checked block-by-block:
        if (c <= 0x2FEF) {
            if (c < 0x300) {
                if (c < 0x00C0) { // 8-bit ctrl chars
                    return false;
                }
                // most of the rest are fine...
                return (c != 0xD7 && c != 0xF7);
            }
            if (c >= 0x2C00) {
                // 0x2C00 - 0x2FEF are ok
                return true;
            }
            if (c < 0x370 || c > 0x218F) {
                // 0x300 - 0x36F, 0x2190 - 0x2BFF invalid
                return false;
            }
            if (c < 0x2000) {
                // 0x370 - 0x37D, 0x37F - 0x1FFF are ok
                return (c != 0x37E);
            }
            if (c >= 0x2070) {
                // 0x2070 - 0x218F are ok
                return (c <= 0x218F);
            }
            // And finally, 0x200C - 0x200D
            return (c == 0x200C || c == 0x200D);
        }

        // 0x3000 and above:
        if (c >= 0x3001) {
            /* Hmmh, let's allow high surrogates here, without checking
             * that they are properly followed... crude basic support,
             * I know, but allows valid combinations, just doesn't catch
             * invalid ones
             */
            if (c <= 0xDBFF) { // 0x3001 - 0xD7FF (chars),
                // 0xD800 - 0xDBFF (high surrogate) are ok (unlike DC00-DFFF)
                return true;
            }
            if (c >= 0xF900 && c <= 0xFFFD) {
                /* Check above removes low surrogate (since one can not
                 * START an identifier), and byte-order markers..
                 */
                return (c <= 0xFDCF || c >= 0xFDF0);
            }
        }

        return false;
    }

    public final static boolean is11NameChar(char c)
    {
        // Others are checked block-by-block:
        if (c <= 0x2FEF) {
            if (c < 0x2000) { // only 8-bit ctrl chars and 0x37E to filter out
                return (c >= 0x00C0 && c != 0x37E|| (c == 0xB7);
            }
            if (c >= 0x2C00) {
                // 0x100 - 0x1FFF, 0x2C00 - 0x2FEF are ok
                return true;
            }
            if (c < 0x200C || c > 0x218F) {
                // 0x2000 - 0x200B, 0x2190 - 0x2BFF invalid
                return false;
            }
            if (c >= 0x2070) {
                // 0x2070 - 0x218F are ok
                return true;
            }
            // And finally, 0x200C - 0x200D, 0x203F - 0x2040 are ok
            return (c == 0x200C || c == 0x200D
                || c == 0x203F || c == 0x2040);
        }

        // 0x3000 and above:
        if (c >= 0x3001) {
            /* Hmmh, let's allow surrogate heres, without checking that
             * they have proper ordering. For non-first name chars, both are
             * ok, for valid names. Crude basic support,
             * I know, but allows valid combinations, just doesn't catch
             * invalid ones
             */
            if (c <= 0xDFFF) { // 0x3001 - 0xD7FF (chars),
                // 0xD800 - 0xDFFF (high, low surrogate) are ok:
                return true;
            }
            if (c >= 0xF900 && c <= 0xFFFD) {
                /* Check above removes other invalid chars (below valid
                 * range), and byte-order markers (0xFFFE, 0xFFFF).
                 */
                return (c <= 0xFDCF || c >= 0xFDF0);
            }
        }

        return false;
    }

    private static void SETBITS(int[] array, int start, int end)
    {
        int bit1 = (start & 31);
        int bit2 = (end 31);
        start >>= 5;
        end >>= 5;

        /* Ok; this is not perfectly optimal, but should be good enough...
         * we'll only do one-by-one at the ends.
         */
        if (start == end) {
            for (; bit1 <= bit2; ++bit1) {
                array[start|= (<< bit1);
            }
        else {
            for (int bit = bit1; bit <= 31; ++bit) {
                array[start|= (<< bit);
            }
            while (++start < end) {
                array[start= -1;
            }
            for (int bit = 0; bit <= bit2; ++bit) {
                array[end|= (<< bit);
            }
        }
    }

    private static void SETBITS(int[] array, int point) {
        int ix = (point >> 5);
        int bit = (point & 31);

        array[ix|= (<< bit);
    }
}

   
    
    
    
  
Related examples in the same category
1. XMLEncoder a bean
2. Returns true if the argument, a UCS-4 character code, is valid in XML documents.
3. XML-related tasks and java.io Readers: IETF standard encoding names, automatic detection of most XML encodings
4. Xml Encoding Sniffer
5. Returns true if the character is an XML "letter"
6. XML character properties
7. Encode Xml Attribute
8. Escape / unescape special chars according XML specifications
9. Verify whether the specified character conforms to the XML 1.0 definition of whitespace
10. Returns true if the character is a non-initial character in names according to the XML recommendation
11. Provides HTML and XML entity utilities.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.