characterdata.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 993 行 · 第 1/5 页
JAVA
993 行
/* * @(#)CharacterData.java 1.6 06/10/10 * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package java.lang;/** The CharacterData class encapsulates the large tables found in Java.lang.Character. */class CharacterData { /* The character properties are currently encoded into 32 bits in the following manner: 1 bit mirrored property 4 bits directionality property 9 bits signed offset used for converting case 1 bit if 1, adding the signed offset converts the character to lowercase 1 bit if 1, subtracting the signed offset converts the character to uppercase 1 bit if 1, this character has a titlecase equivalent (possibly itself) 3 bits 0 may not be part of an identifier 1 ignorable control; may continue a Unicode identifier or Java identifier 2 may continue a Java identifier but not a Unicode identifier (unused) 3 may continue a Unicode identifier or Java identifier 4 is a Java whitespace character 5 may start or continue a Java identifier; may continue but not start a Unicode identifier (underscores) 6 may start or continue a Java identifier but not a Unicode identifier ($) 7 may start or continue a Unicode identifier or Java identifier Thus: 5, 6, 7 may start a Java identifier 1, 2, 3, 5, 6, 7 may continue a Java identifier 7 may start a Unicode identifier 1, 3, 5, 7 may continue a Unicode identifier 1 is ignorable within an identifier 4 is Java whitespace 2 bits 0 this character has no numeric property 1 adding the digit offset to the character code and then masking with 0x1F will produce the desired numeric value 2 this character has a "strange" numeric value 3 a Java supradecimal digit: adding the digit offset to the character code, then masking with 0x1F, then adding 10 will produce the desired numeric value 5 bits digit offset 5 bits character type The encoding of character properties is subject to change at any time. */ static int getProperties(char ch) { return A[Y[(X[ch>>5]<<4)|((ch>>1)&0xF)]|(ch&0x1)]; } static int getType(char ch) { return (getProperties(ch) & 0x1F); } static boolean isLowerCase(char ch) { return getType(ch) == Character.LOWERCASE_LETTER; } static boolean isUpperCase(char ch) { return getType(ch) == Character.UPPERCASE_LETTER; } static boolean isTitleCase(char ch) { return getType(ch) == Character.TITLECASE_LETTER; } static boolean isDigit(char ch) { return getType(ch) == Character.DECIMAL_DIGIT_NUMBER; } static boolean isDefined(char ch) { return getType(ch) != Character.UNASSIGNED; } static boolean isLetter(char ch) { return (((((1 << Character.UPPERCASE_LETTER) | (1 << Character.LOWERCASE_LETTER) | (1 << Character.TITLECASE_LETTER) | (1 << Character.MODIFIER_LETTER) | (1 << Character.OTHER_LETTER)) >> getType(ch)) & 1) != 0); } static boolean isLetterOrDigit(char ch) { return (((((1 << Character.UPPERCASE_LETTER) | (1 << Character.LOWERCASE_LETTER) | (1 << Character.TITLECASE_LETTER) | (1 << Character.MODIFIER_LETTER) | (1 << Character.OTHER_LETTER) | (1 << Character.DECIMAL_DIGIT_NUMBER)) >> getType(ch)) & 1) != 0); } static boolean isSpaceChar(char ch) { return (((((1 << Character.SPACE_SEPARATOR) | (1 << Character.LINE_SEPARATOR) | (1 << Character.PARAGRAPH_SEPARATOR)) >> getType(ch)) & 1) != 0); } static boolean isJavaIdentifierStart(char ch) { return (getProperties(ch) & 0x00007000) >= 0x00005000; } static boolean isJavaIdentifierPart(char ch) { return (getProperties(ch) & 0x00003000) != 0; } static boolean isUnicodeIdentifierStart(char ch) { return (getProperties(ch) & 0x00007000) == 0x00007000; } static boolean isUnicodeIdentifierPart(char ch) { return (getProperties(ch)& 0x00001000) != 0; } static boolean isIdentifierIgnorable(char ch) { return (getProperties(ch) & 0x00007000) == 0x00001000; } static char toLowerCase(char ch) { char mapChar = ch; int val = getProperties(ch); if ((val & 0x00020000) != 0) { if ((val & 0x07FC0000) == 0x07FC0000) { switch(ch) { // map the offset overflow chars case '\u2126' : mapChar = '\u03C9'; break; case '\u212A' : mapChar = '\u006B'; break; case '\u212B' : mapChar = '\u00E5'; break; // map the titlecase chars with both a 1:M uppercase map // and a lowercase map case '\u1F88' : mapChar = '\u1F80'; break; case '\u1F89' : mapChar = '\u1F81'; break; case '\u1F8A' : mapChar = '\u1F82'; break; case '\u1F8B' : mapChar = '\u1F83'; break; case '\u1F8C' : mapChar = '\u1F84'; break; case '\u1F8D' : mapChar = '\u1F85'; break; case '\u1F8E' : mapChar = '\u1F86'; break; case '\u1F8F' : mapChar = '\u1F87'; break; case '\u1F98' : mapChar = '\u1F90'; break; case '\u1F99' : mapChar = '\u1F91'; break; case '\u1F9A' : mapChar = '\u1F92'; break; case '\u1F9B' : mapChar = '\u1F93'; break; case '\u1F9C' : mapChar = '\u1F94'; break; case '\u1F9D' : mapChar = '\u1F95'; break; case '\u1F9E' : mapChar = '\u1F96'; break; case '\u1F9F' : mapChar = '\u1F97'; break; case '\u1FA8' : mapChar = '\u1FA0'; break; case '\u1FA9' : mapChar = '\u1FA1'; break; case '\u1FAA' : mapChar = '\u1FA2'; break; case '\u1FAB' : mapChar = '\u1FA3'; break; case '\u1FAC' : mapChar = '\u1FA4'; break; case '\u1FAD' : mapChar = '\u1FA5'; break; case '\u1FAE' : mapChar = '\u1FA6'; break; case '\u1FAF' : mapChar = '\u1FA7'; break; case '\u1FBC' : mapChar = '\u1FB3'; break; case '\u1FCC' : mapChar = '\u1FC3'; break; case '\u1FFC' : mapChar = '\u1FF3'; break; // default mapChar is already set, so no // need to redo it here. // default : mapChar = ch; } } else { int offset = val << 5 >> (5+18); mapChar = (char)(ch + offset); } } return mapChar; } static char toUpperCase(char ch) { char mapChar = ch; int val = getProperties(ch);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?