What character is that?

My ScreenScraping Teaching tool I’m using to create the Poker Copilot Zoom Poker HUD shows an image on screen and what character it thinks that image contains. I tell the Teaching tool if the character is correct or not.

Problem is, I can’t tell whether it thinks an image is an upper case 0 or the number 0. I can’t tell if it thinks a letter is an upper case i (l) or a lower case L (l).

So I’ve created a small Java class which will give me a textual description of a character. Now it will tell me that l is either:

UPPERCASE LETTER I

or

LOWERCASE LETTER L

It will tell me that 0 is

UPPERCASE LETTER O

or

DECIMAL DIGIT NUMBER 0

The Java class is called Characters, and the source code follows:


public class Characters {

public static String getDescription(char ch) {
return CharacterType.getDescription(ch);
}

private static enum CharacterType {

UNASSIGNED,
UPPERCASE_LETTER,
LOWERCASE_LETTER,
TITLECASE_LETTER,
MODIFIER_LETTER,
OTHER_LETTER,
NON_SPACING_MARK,
ENCLOSING_MARK,
COMBINING_SPACING_MARK,
DECIMAL_DIGIT_NUMBER,
LETTER_NUMBER,
OTHER_NUMBER,
SPACE_SEPARATOR,
LINE_SEPARATOR,
PARAGRAPH_SEPARATOR,
CONTROL,
FORMAT,
NOT_USED,
PRIVATE_USE,
SURROGATE,
DASH_PUNCTUATION,
START_PUNCTUATION,
END_PUNCTUATION,
CONNECTOR_PUNCTUATION,
OTHER_PUNCTUATION,
MATH_SYMBOL,
CURRENCY_SYMBOL,
MODIFIER_SYMBOL,
OTHER_SYMBOL,
INITIAL_QUOTE_PUNCTUATION,
FINAL_QUOTE_PUNCTUATION;

private static String getDescription(final int c) {
final int type = Character.getType(c);
final CharacterType characterType = CharacterType.values()[type];
return characterType.toString().replace('_', ' ') + ' ' + (char) Character.toUpperCase(c);
}

}
}

 

Some sample usage:


System.out.println(Characters.getDescription('O'));
System.out.println(Characters.getDescription('0'));