/*
*
*
* Copyright 1990-2007 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 com.sun.cldc.i18n.uclc;
import java.io.*;
import com.sun.cldc.i18n.*;
/**
* Default class converting the case of characters.
*
* @version 1.0 04/04/2000
*/
public class DefaultCaseConverter {
/**
* Determines if the specified character is a lowercase character.
* The default case converter in CLDC only supports the ISO Latin-1
* range of characters.
* <p>
* Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF),
* the following are lowercase:
* <p>
* 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
* \u00DF \u00E0 \u00E1 \u00E2 \u00E3 \u00E4 \u00E5 \u00E6 \u00E7
* \u00E8 \u00E9 \u00EA \u00EB \u00EC \u00ED \u00EE \u00EF \u00F0
* \u00F1 \u00F2 \u00F3 \u00F4 \u00F5 \u00F6 \u00F8 \u00F9 \u00FA
* \u00FB \u00FC \u00FD \u00FE \u00FF
*
* @param ch the character to be tested.
* @return <code>true</code> if the character is lowercase;
* <code>false</code> otherwise.
* @since JDK1.0
*/
public static boolean isLowerCase(char ch) {
return (ch >= 'a' && ch <= 'z')
|| (ch >= 0xDF && ch <= 0xF6)
|| (ch >= 0xF8 && ch <= 0xFF);
}
/**
* Determines if the specified character is an uppercase character.
* The default case converter in CLDC only supports the ISO Latin-1
* range of characters.
* <p>
* Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF),
* the following are uppercase:
* <p>
* 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
* \u00C0 \u00C1 \u00C2 \u00C3 \u00C4 \u00C5 \u00C6 \u00C7
* \u00C8 \u00C9 \u00CA \u00CB \u00CC \u00CD \u00CE \u00CF \u00D0
* \u00D1 \u00D2 \u00D3 \u00D4 \u00D5 \u00D6 \u00D8 \u00D9 \u00DA
* \u00DB \u00DC \u00DD \u00DE
*
* @param ch the character to be tested.
* @return <code>true</code> if the character is uppercase;
* <code>false</code> otherwise.
* @see java.lang.Character#isLowerCase(char)
* @see java.lang.Character#toUpperCase(char)
* @since 1.0
*/
public static boolean isUpperCase(char ch) {
return (ch >= 'A' && ch <= 'Z')
|| (ch >= 0xC0 && ch <= 0xD6)
|| (ch >= 0xD8 && ch <= 0xDE );
}
/**
* The given character is mapped to its lowercase equivalent; if the
* character has no lowercase equivalent, the character itself is
* returned. The default case converter in CLDC only supports
* the ISO Latin-1 range of characters.
*
* @param ch the character to be converted.
* @return the lowercase equivalent of the character, if any;
* otherwise the character itself.
* @see java.lang.Character#isLowerCase(char)
* @see java.lang.Character#isUpperCase(char)
* @see java.lang.Character#toUpperCase(char)
* @since JDK1.0
*/
public static char toLowerCase(char ch) {
if (isUpperCase(ch)) {
if (ch <= 'Z') {
return (char)(ch + ('a' - 'A'));
} else {
return (char)(ch + 0x20);
}
} else {
return ch;
}
}
/**
* Converts the character argument to uppercase; if the
* character has no lowercase equivalent, the character itself is
* returned. The default case converter in CLDC only supports
* the ISO Latin-1 range of characters.
*
* @param ch the character to be converted.
* @return the uppercase equivalent of the character, if any;
* otherwise the character itself.
* @see java.lang.Character#isLowerCase(char)
* @see java.lang.Character#isUpperCase(char)
* @see java.lang.Character#toLowerCase(char)
* @since JDK1.0
*/
public static char toUpperCase(char ch) {
if (isLowerCase(ch)) {
if (ch <= 'z') {
return (char)(ch - ('a' - 'A'));
} else {
return (char)(ch - 0x20);
}
} else {
return ch;
}
}
/**
* Determines if the specified character is a digit.
* This is currently only supported for ISO Latin-1 digits: "0" through "9".
*
* @param ch the character to be tested.
* @return <code>true</code> if the character is a digit;
* <code>false</code> otherwise.
* @since JDK1.0
*/
public static boolean isDigit(char ch) {
return ch >= '0' && ch <= '9';
}
/**
* Returns the numeric value of the character <code>ch</code>
* in the specified radix.
* This is only supported for ISO Latin-1 characters.
*
* @param ch the character to be converted.
* @param radix the radix.
* @return the numeric value represented by the character in the
* specified radix.
* @see java.lang.Character#isDigit(char)
* @since JDK1.0
*/
public static int digit(char ch, int radix) {
int value = -1;
if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
if (isDigit(ch)) {
value = ch - '0';
}
else if (isUpperCase(ch) || isLowerCase(ch)) {
// Java supradecimal digit
value = (ch & 0x1F) + 9;
}
}
return (value < radix) ? value : -1;
}
}
|