Skip to content

Commit d7cbe71

Browse files
committed
CharUtil
1 parent 9f6386f commit d7cbe71

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.blogtree.util.common;
2+
3+
/**
4+
* char工具类
5+
*
6+
* @author AlanGeeker
7+
*/
8+
public class CharUtil {
9+
10+
private static char char_A = 'A';
11+
private static char char_Z = 'Z';
12+
private static char char_a = 'a';
13+
private static char char_z = 'z';
14+
15+
/**
16+
* char 英文字母小写
17+
*/
18+
public static char toLowerCase(char c) {
19+
if (c >= char_A && c <= char_Z) {
20+
c += 32;
21+
}
22+
return c;
23+
}
24+
25+
/**
26+
* char 英文字母小写
27+
*/
28+
public static char toUpperCase(char c) {
29+
if (c >= char_a && c <= char_z) {
30+
c -= 32;
31+
}
32+
return c;
33+
}
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.blogtree.util.common;
2+
3+
import org.blogtree.util.base.BaseTest;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.*;
7+
8+
public class CharUtilTest extends BaseTest {
9+
10+
@Test
11+
public void toLowerCase() {
12+
assert 'a' == CharUtil.toLowerCase('A');
13+
assert 'b' == CharUtil.toLowerCase('B');
14+
assert 'y' == CharUtil.toLowerCase('Y');
15+
assert 'z' == CharUtil.toLowerCase('Z');
16+
assert '3' == CharUtil.toLowerCase('3');
17+
assert '-' == CharUtil.toLowerCase('-');
18+
assert ' ' == CharUtil.toLowerCase(' ');
19+
}
20+
21+
@Test
22+
public void toUpperCase() {
23+
assert 'A' == CharUtil.toUpperCase('a');
24+
assert 'B' == CharUtil.toUpperCase('b');
25+
assert 'Y' == CharUtil.toUpperCase('y');
26+
assert 'Z' == CharUtil.toUpperCase('z');
27+
assert '3' == CharUtil.toLowerCase('3');
28+
assert '-' == CharUtil.toLowerCase('-');
29+
assert ' ' == CharUtil.toLowerCase(' ');
30+
}
31+
}

0 commit comments

Comments
 (0)