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