001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.cldc.i18n.uclc;
028:
029: import java.io.*;
030: import com.sun.cldc.i18n.*;
031:
032: /**
033: * Default class converting the case of characters.
034: *
035: * @version 1.0 04/04/2000
036: */
037: public class DefaultCaseConverter {
038:
039: /**
040: * Determines if the specified character is a lowercase character.
041: * The default case converter in CLDC only supports the ISO Latin-1
042: * range of characters.
043: * <p>
044: * Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF),
045: * the following are lowercase:
046: * <p>
047: * a b c d e f g h i j k l m n o p q r s t u v w x y z
048: * \u00DF \u00E0 \u00E1 \u00E2 \u00E3 \u00E4 \u00E5 \u00E6 \u00E7
049: * \u00E8 \u00E9 \u00EA \u00EB \u00EC \u00ED \u00EE \u00EF \u00F0
050: * \u00F1 \u00F2 \u00F3 \u00F4 \u00F5 \u00F6 \u00F8 \u00F9 \u00FA
051: * \u00FB \u00FC \u00FD \u00FE \u00FF
052: *
053: * @param ch the character to be tested.
054: * @return <code>true</code> if the character is lowercase;
055: * <code>false</code> otherwise.
056: * @since JDK1.0
057: */
058: public static boolean isLowerCase(char ch) {
059: return (ch >= 'a' && ch <= 'z') || (ch >= 0xDF && ch <= 0xF6)
060: || (ch >= 0xF8 && ch <= 0xFF);
061: }
062:
063: /**
064: * Determines if the specified character is an uppercase character.
065: * The default case converter in CLDC only supports the ISO Latin-1
066: * range of characters.
067: * <p>
068: * Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF),
069: * the following are uppercase:
070: * <p>
071: * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
072: * \u00C0 \u00C1 \u00C2 \u00C3 \u00C4 \u00C5 \u00C6 \u00C7
073: * \u00C8 \u00C9 \u00CA \u00CB \u00CC \u00CD \u00CE \u00CF \u00D0
074: * \u00D1 \u00D2 \u00D3 \u00D4 \u00D5 \u00D6 \u00D8 \u00D9 \u00DA
075: * \u00DB \u00DC \u00DD \u00DE
076: *
077: * @param ch the character to be tested.
078: * @return <code>true</code> if the character is uppercase;
079: * <code>false</code> otherwise.
080: * @see java.lang.Character#isLowerCase(char)
081: * @see java.lang.Character#toUpperCase(char)
082: * @since 1.0
083: */
084: public static boolean isUpperCase(char ch) {
085: return (ch >= 'A' && ch <= 'Z') || (ch >= 0xC0 && ch <= 0xD6)
086: || (ch >= 0xD8 && ch <= 0xDE);
087: }
088:
089: /**
090: * The given character is mapped to its lowercase equivalent; if the
091: * character has no lowercase equivalent, the character itself is
092: * returned. The default case converter in CLDC only supports
093: * the ISO Latin-1 range of characters.
094: *
095: * @param ch the character to be converted.
096: * @return the lowercase equivalent of the character, if any;
097: * otherwise the character itself.
098: * @see java.lang.Character#isLowerCase(char)
099: * @see java.lang.Character#isUpperCase(char)
100: * @see java.lang.Character#toUpperCase(char)
101: * @since JDK1.0
102: */
103: public static char toLowerCase(char ch) {
104: if (isUpperCase(ch)) {
105: if (ch <= 'Z') {
106: return (char) (ch + ('a' - 'A'));
107: } else {
108: return (char) (ch + 0x20);
109: }
110: } else {
111: return ch;
112: }
113: }
114:
115: /**
116: * Converts the character argument to uppercase; if the
117: * character has no lowercase equivalent, the character itself is
118: * returned. The default case converter in CLDC only supports
119: * the ISO Latin-1 range of characters.
120: *
121: * @param ch the character to be converted.
122: * @return the uppercase equivalent of the character, if any;
123: * otherwise the character itself.
124: * @see java.lang.Character#isLowerCase(char)
125: * @see java.lang.Character#isUpperCase(char)
126: * @see java.lang.Character#toLowerCase(char)
127: * @since JDK1.0
128: */
129: public static char toUpperCase(char ch) {
130: if (isLowerCase(ch)) {
131: if (ch <= 'z') {
132: return (char) (ch - ('a' - 'A'));
133: } else {
134: return (char) (ch - 0x20);
135: }
136: } else {
137: return ch;
138: }
139: }
140:
141: /**
142: * Determines if the specified character is a digit.
143: * This is currently only supported for ISO Latin-1 digits: "0" through "9".
144: *
145: * @param ch the character to be tested.
146: * @return <code>true</code> if the character is a digit;
147: * <code>false</code> otherwise.
148: * @since JDK1.0
149: */
150: public static boolean isDigit(char ch) {
151: return ch >= '0' && ch <= '9';
152: }
153:
154: /**
155: * Returns the numeric value of the character <code>ch</code>
156: * in the specified radix.
157: * This is only supported for ISO Latin-1 characters.
158: *
159: * @param ch the character to be converted.
160: * @param radix the radix.
161: * @return the numeric value represented by the character in the
162: * specified radix.
163: * @see java.lang.Character#isDigit(char)
164: * @since JDK1.0
165: */
166: public static int digit(char ch, int radix) {
167: int value = -1;
168: if (radix >= Character.MIN_RADIX
169: && radix <= Character.MAX_RADIX) {
170: if (isDigit(ch)) {
171: value = ch - '0';
172: } else if (isUpperCase(ch) || isLowerCase(ch)) {
173: // Java supradecimal digit
174: value = (ch & 0x1F) + 9;
175: }
176: }
177: return (value < radix) ? value : -1;
178: }
179:
180: }
|