|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.CharUtil
public final class CharUtil
Provides static utility methods for dealing with char
s.
Note that the argument type for many of the methods is of int
type, as opposed to char
type.
This was deliberately chosen for these reasons:
Reader
s return int
values when do single character reads, in order to indicate EOF by returning -1.
So, using int
type arguments allows this class's methods to handle EOF values, freeing the programmer from having to first check.
char
argument to an int
anyways,
so it is never slower to do a single cast at the start
This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).
Nested Class Summary | |
---|---|
static class |
CharUtil.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private static int |
maxAscii
The maximum (int) value that a valid US-ASCII (i.e. 7 bit) char can have. |
private static int |
maxChar
The maximum (int) value that a valid Java char can have. |
private static int |
minAscii
The minimum (int) value that a valid US-ASCII (i.e. 7 bit) char can have. |
private static int |
minChar
The minimum (int) value that a valid Java char can have. |
Constructor Summary | |
---|---|
private |
CharUtil()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class. |
Method Summary | |
---|---|
static String |
getEscapeForLiteral(char c)
Returns the "simple" (i.e. 2 char) escape sequence for the supplied char, which is suitable for appearing in a Java char or String Literal. |
static boolean |
hasEscapeForLiteral(char c)
Reports whether or not the supplied char has a "simple" escape sequence that may appear in a Java char or String Literal. |
static boolean |
isAscii(int c)
Determines whether or not c has a value that a Java char can represent. |
static boolean |
isChar(int c)
Determines whether or not c has a value that a Java char can represent. |
static boolean |
isDecimalDigit(int c)
Determines whether or not c represents a decimal digit (i.e. '0', '1', ..., '9'). |
static boolean |
isLineEnd(int c)
Determines whether or not c represents a (lower or upper case) Roman Letter (i.e. |
static boolean |
isRomanLetter(int c)
Determines whether or not c represents a (lower or upper case) Roman Letter (i.e. |
static boolean |
isRomanLetterLowerCase(int c)
Determines whether or not c represents a lower case Roman Letter (i.e. |
static boolean |
isRomanLetterUpperCase(int c)
Determines whether or not c represents an upper case Roman Letter (i.e. |
static boolean |
matches(char c1,
char c2,
boolean isCaseSensitive)
Determines whether or not c1 and c2 are matching char values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int minAscii
private static final int maxAscii
private static final int minChar
private static final int maxChar
Constructor Detail |
---|
private CharUtil()
Method Detail |
---|
public static boolean isAscii(int c)
char
can represent.
public static boolean isChar(int c)
char
can represent.
public static boolean isDecimalDigit(int c)
public static boolean isLineEnd(int c)
public static boolean isRomanLetter(int c)
public static boolean isRomanLetterLowerCase(int c)
public static boolean isRomanLetterUpperCase(int c)
public static boolean hasEscapeForLiteral(char c)
public static String getEscapeForLiteral(char c) throws IllegalArgumentException
IllegalArgumentException
- if the char has no "simple" escape
(i.e. if CharUtil.hasEscapeForLiteral(c) returns false)public static boolean matches(char c1, char c2, boolean isCaseSensitive)
c1 == c2
.
Else if isCaseSensitive == false
, then c1 and c2 are recompared on a case insensitive basis.
Only if that too fails is false returned.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |