Java tutorial
//package com.java2s; /* * Qizx/open 4.1 * * This code is the open-source version of Qizx. * Copyright (C) 2004-2009 Axyana Software -- All rights reserved. * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Initial Developer of the Original Code is Xavier Franc - Axyana Software. * */ public class Main { /** * Tests if specified string is a lexically correct Name. * * @param s string to be tested * @return <code>true</code> if test is successful; <code>false</code> * otherwise */ public static final boolean isName(String s) { int count; if (s == null || (count = s.length()) == 0) return false; char c = s.charAt(0); switch (c) { case '_': case ':': break; default: if (!Character.isLetter(c)) return false; } for (int i = 1; i < count; ++i) { if (!isNameChar(s.charAt(i))) return false; } return true; } public static final boolean isNameChar(char c) { switch (c) { case '.': case '-': case '_': case ':': break; case 0x05BF: case 0x05C4: case 0x0670: case 0x093C: case 0x094D: case 0x09BC: case 0x09BE: case 0x09BF: case 0x09D7: case 0x0A02: case 0x0A3C: case 0x0A3E: case 0x0A3F: case 0x0ABC: case 0x0B3C: case 0x0BD7: case 0x0D57: case 0x0E31: case 0x0EB1: case 0x0F35: case 0x0F37: case 0x0F39: case 0x0F3E: case 0x0F3F: case 0x0F97: case 0x0FB9: case 0x20E1: case 0x3099: case 0x309A: // CombiningChar. break; case 0x00B7: case 0x02D0: case 0x02D1: case 0x0387: case 0x0640: case 0x0E46: case 0x0EC6: case 0x3005: // Extender. break; default: if (Character.isLetterOrDigit(c)) break; if ((c >= 0x0300 && c <= 0x0345) || (c >= 0x0360 && c <= 0x0361) || (c >= 0x0483 && c <= 0x0486) || (c >= 0x0591 && c <= 0x05A1) || (c >= 0x05A3 && c <= 0x05B9) || (c >= 0x05BB && c <= 0x05BD) || (c >= 0x05C1 && c <= 0x05C2) || (c >= 0x064B && c <= 0x0652) || (c >= 0x06D6 && c <= 0x06DC) || (c >= 0x06DD && c <= 0x06DF) || (c >= 0x06E0 && c <= 0x06E4) || (c >= 0x06E7 && c <= 0x06E8) || (c >= 0x06EA && c <= 0x06ED) || (c >= 0x0901 && c <= 0x0903) || (c >= 0x093E && c <= 0x094C) || (c >= 0x0951 && c <= 0x0954) || (c >= 0x0962 && c <= 0x0963) || (c >= 0x0981 && c <= 0x0983) || (c >= 0x09C0 && c <= 0x09C4) || (c >= 0x09C7 && c <= 0x09C8) || (c >= 0x09CB && c <= 0x09CD) || (c >= 0x09E2 && c <= 0x09E3) || (c >= 0x0A40 && c <= 0x0A42) || (c >= 0x0A47 && c <= 0x0A48) || (c >= 0x0A4B && c <= 0x0A4D) || (c >= 0x0A70 && c <= 0x0A71) || (c >= 0x0A81 && c <= 0x0A83) || (c >= 0x0ABE && c <= 0x0AC5) || (c >= 0x0AC7 && c <= 0x0AC9) || (c >= 0x0ACB && c <= 0x0ACD) || (c >= 0x0B01 && c <= 0x0B03) || (c >= 0x0B3E && c <= 0x0B43) || (c >= 0x0B47 && c <= 0x0B48) || (c >= 0x0B4B && c <= 0x0B4D) || (c >= 0x0B56 && c <= 0x0B57) || (c >= 0x0B82 && c <= 0x0B83) || (c >= 0x0BBE && c <= 0x0BC2) || (c >= 0x0BC6 && c <= 0x0BC8) || (c >= 0x0BCA && c <= 0x0BCD) || (c >= 0x0C01 && c <= 0x0C03) || (c >= 0x0C3E && c <= 0x0C44) || (c >= 0x0C46 && c <= 0x0C48) || (c >= 0x0C4A && c <= 0x0C4D) || (c >= 0x0C55 && c <= 0x0C56) || (c >= 0x0C82 && c <= 0x0C83) || (c >= 0x0CBE && c <= 0x0CC4) || (c >= 0x0CC6 && c <= 0x0CC8) || (c >= 0x0CCA && c <= 0x0CCD) || (c >= 0x0CD5 && c <= 0x0CD6) || (c >= 0x0D02 && c <= 0x0D03) || (c >= 0x0D3E && c <= 0x0D43) || (c >= 0x0D46 && c <= 0x0D48) || (c >= 0x0D4A && c <= 0x0D4D) || (c >= 0x0E34 && c <= 0x0E3A) || (c >= 0x0E47 && c <= 0x0E4E) || (c >= 0x0EB4 && c <= 0x0EB9) || (c >= 0x0EBB && c <= 0x0EBC) || (c >= 0x0EC8 && c <= 0x0ECD) || (c >= 0x0F18 && c <= 0x0F19) || (c >= 0x0F71 && c <= 0x0F84) || (c >= 0x0F86 && c <= 0x0F8B) || (c >= 0x0F90 && c <= 0x0F95) || (c >= 0x0F99 && c <= 0x0FAD) || (c >= 0x0FB1 && c <= 0x0FB7) || (c >= 0x20D0 && c <= 0x20DC) || (c >= 0x302A && c <= 0x302F)) // CombiningChar break; if ((c >= 0x3031 && c <= 0x3035) || (c >= 0x309D && c <= 0x309E) || (c >= 0x30FC && c <= 0x30FE)) // Extender. break; return false; } return true; } }