|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sage.accpac.sm.ASCIIComparer
@ThreadSafe public final class ASCIIComparer
A class providing for ASCII handling of strings.
Frequently we perform tests to see if an input string is equal without regard
to case to a pure ASCII string. See equalsIgnoreCase(String,String)
.
For simplicity we also like to convert strings to a consistent case (either
lower or upper). See toLowerCase(String)
and
toUpperCase(String)
for suitable functions.
Sometimes we know, by context, that we have an ASCII string that we can
safely convert to lower case using e.g. toLowerCase(String)
, but
sometimes we might not know. Rather than catching an exception we may prefer
to use isASCII(String)
to see if the argument is a valid string to
pass to it.
In our frameworks we frequently use strings that are pure ASCII which makes it simpler to be well defined. In the System Manager core C code we have already noted that there is quite an improvement in performance by switching from the locale-specific case-insensitive comparisons to a specialised version that only allows for ASCII characters. The improvement in Java is less pronounced but the advantage is that it is more well-defined.
Method Summary | |
---|---|
static boolean |
equalsIgnoreCase(java.lang.String firstString,
java.lang.String secondString)
returns true if and only if both strings are pure ASCII strings and they are equal without regard to case. |
static boolean |
isASCII(java.lang.String string)
returns true if and only if the input is a pure ASCII string |
static java.lang.String |
toLowerCase(java.lang.String string)
returns a String containing the lower case conversion of the pure ASCII input, throwing an exception if it is not pure ASCII. |
static java.lang.String |
toUpperCase(java.lang.String string)
returns a String containing the lower case conversion of the pure ASCII input, throwing an exception if it is not pure ASCII. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean equalsIgnoreCase(java.lang.String firstString, java.lang.String secondString)
It returns false if either string (or both) is not a pure ASCII string; it does not throw an exception. This means you do not need to test first of all to see if the string is ASCII before calling this function. (neither, however, can be null references).
A string is a pure ASCII string if all of the characters in it are in the range of ASCII characters (i.e. have code points between 0 and 127).
On average on a reasonable computer a short string comparison takes of the order of 1 microsecond when comparing random strings.
firstString
- the first stringsecondString
- the second string
java.lang.NullPointerException
- if either or both of the arguments are null references.public static java.lang.String toLowerCase(java.lang.String string)
isASCII(String)
to check that the argument is pure ASCII.
string
- the string to convert, which must not be a null reference and
must consist only of ASCII characters.
java.lang.IllegalArgumentException
- if the string is not pure ASCII
java.lang.NullPointerException
- if the string is a null referenceisASCII(String)
public static java.lang.String toUpperCase(java.lang.String string)
isASCII(String)
to check that the argument is pure ASCII.
string
- the string to convert, which must not be a null reference and
must consist only of ASCII characters.
java.lang.IllegalArgumentException
- if the string is not pure ASCII
java.lang.NullPointerException
- if the string is a null referenceisASCII(String)
public static boolean isASCII(java.lang.String string)
string
- the string to check
java.lang.NullPointerException
- if the string is a null reference
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |