1 package org.kuali.common.util;
2
3 public final class Ascii {
4
5 private Ascii() {
6 }
7
8 private static final int LETTER_OFFSET = 13;
9 private static final int NUMBER_OFFSET = 5;
10 private static final char NUMBER_MIDPOINT = '4';
11 private static final char LCASE_MIDPOINT = 'm';
12 private static final char UCASE_MIDPOINT = 'M';
13
14
15
16
17 public static boolean isLetter(char c) {
18 return isLowerCase(c) || isUpperCase(c);
19 }
20
21
22
23
24 public static boolean isDigit(char c) {
25 return c >= '0' && c <= '9';
26 }
27
28
29
30
31 public static boolean isLowerCase(char c) {
32 return c >= 'a' && c <= 'z';
33 }
34
35
36
37
38 public static boolean isUpperCase(char c) {
39 return c >= 'A' && c <= 'Z';
40 }
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public static char flip(char c) {
55 if (isLowerCase(c)) {
56 if (c > LCASE_MIDPOINT) {
57 return (char) ((int) c - LETTER_OFFSET);
58 } else {
59 return (char) ((int) c + LETTER_OFFSET);
60 }
61 } else if (isUpperCase(c)) {
62 if (c > UCASE_MIDPOINT) {
63 return (char) ((int) c - LETTER_OFFSET);
64 } else {
65 return (char) ((int) c + LETTER_OFFSET);
66 }
67 } else if (isDigit(c)) {
68 if (c > NUMBER_MIDPOINT) {
69 return (char) ((int) c - NUMBER_OFFSET);
70 } else {
71 return (char) ((int) c + NUMBER_OFFSET);
72 }
73 } else {
74 return c;
75 }
76 }
77
78 }