Exemplo n.º 1
0
 /**
  * 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';
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
 /** @throws Exception */
 @Test
 public void test() throws Exception {
   assertTrue(CharUtil.isAscii('a'));
   assertFalse(CharUtil.isAscii('あ'));
 }
Exemplo n.º 4
0
 public static boolean isName(int c) {
   return c == ':' || c == '_' || CharUtil.isLetter(c);
 }