/** * Converts char digit into integer value. Accepts numeric chars (0 - 9) as well as letter (A-z). */ public static int parseDigit(char digit) { if ((digit >= '0') && (digit <= '9')) { return digit - '0'; } if (CharUtil.isLowercaseAlpha(digit)) { return 10 + digit - 'a'; } return 10 + digit - 'A'; }
/** * Returns the string with all regex controll characters escaped.<br> * The result from this operation should return a pattern which the input string matches.<br> * WARNING: this method does not escape newline characters and for strings containing newline * characters the input will not match the result pattern.<br> * * @param input * @return */ public static String getEscaped(String input) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); boolean escape = CharUtil.isRegexControlChar(ch); if (escape) { sb.append('\\'); } sb.append(ch); } return sb.toString(); }
/** @throws Exception */ @Test public void test() throws Exception { assertTrue(CharUtil.isAscii('a')); assertFalse(CharUtil.isAscii('あ')); }
public static boolean isName(int c) { return c == ':' || c == '_' || CharUtil.isLetter(c); }