Java 怎么实现如果给定字符是XML标准的标记名起始字符,则返回true,否则返回false

2019年8月3日23:26:55Java 怎么实现如果给定字符是XML标准的标记名起始字符,则返回true,否则返回false已关闭评论 332 975字阅读3分15秒

1.简介

Java 怎么实现如果给定字符是XML标准的标记名起始字符,则返回true,否则返回false?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */



public class Main {
    public static void main(String[] argv) throws Exception {
        char c = 'a';
        System.out.println(isNameStartCharacter(c));
    }

    
    public static boolean isNameStartCharacter(char c) {
        if (c == ':' || c == '_') {
            return true;
        }
        if (intervalContains('a', 'z', c) || intervalContains('A', 'Z', c)) {
            return true;
        }
        if (intervalContains(0x00C0, 0x00D6, c)
                || intervalContains(0x00D8, 0x00F6, c)) {
            return true;
        }
        if (intervalContains(0x00F8, 0x02FF, c)
                || intervalContains(0x0370, 0x037D, c)) {
            return true;
        }
        if (intervalContains(0x037F, 0x1FFF, c)
                || intervalContains(0x200C, 0x200D, c)) {
            return true;
        }
        if (intervalContains(0x2070, 0x218F, c)
                || intervalContains(0x2C00, 0x2FEF, c)) {
            return true;
        }
        if (intervalContains(0x3001, 0xD7FF, c)
                || intervalContains(0xF900, 0xFDCF, c)) {
            return true;
        }
        if (intervalContains(0xFDF0, 0xFFFD, c)) {
            return true;
        }
        return false;
    }

    private static boolean intervalContains(int start, int end, int search) {
        assert start <= end;
        return start <= search && end >= search;
    }
}

 
继续阅读