Skip to content

Commit 88b72e1

Browse files
author
Blankj
committed
see 03/03 log
1 parent b5dd1d0 commit 88b72e1

1 file changed

Lines changed: 48 additions & 48 deletions

File tree

utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* author: Blankj
66
* blog : http://blankj.com
77
* time : 2016/08/16
8-
* desc : 字符串相关工具类
8+
* desc : utils about string
99
* </pre>
1010
*/
1111
public final class StringUtils {
@@ -15,30 +15,30 @@ private StringUtils() {
1515
}
1616

1717
/**
18-
* 判断字符串是否为 null 或长度为 0
18+
* Return whether the string is null or 0-length.
1919
*
20-
* @param s 待校验字符串
21-
* @return {@code true}: <br> {@code false}: 不为空
20+
* @param s The string.
21+
* @return {@code true}: yes<br> {@code false}: no
2222
*/
2323
public static boolean isEmpty(final CharSequence s) {
2424
return s == null || s.length() == 0;
2525
}
2626

2727
/**
28-
* 判断字符串是否为 null 或全为空格
28+
* Return whether the string is null or whitespace.
2929
*
30-
* @param s 待校验字符串
31-
* @return {@code true}: null 或全空格<br> {@code false}: 不为 null 且不全空格
30+
* @param s The string.
31+
* @return {@code true}: yes<br> {@code false}: no
3232
*/
3333
public static boolean isTrimEmpty(final String s) {
3434
return (s == null || s.trim().length() == 0);
3535
}
3636

3737
/**
38-
* 判断字符串是否为 null 或全为空白字符
38+
* Return whether the string is null or white space.
3939
*
40-
* @param s 待校验字符串
41-
* @return {@code true}: null 或全空白字符<br> {@code false}: 不为 null 且不全空白字符
40+
* @param s The string.
41+
* @return {@code true}: yes<br> {@code false}: no
4242
*/
4343
public static boolean isSpace(final String s) {
4444
if (s == null) return true;
@@ -51,21 +51,21 @@ public static boolean isSpace(final String s) {
5151
}
5252

5353
/**
54-
* 判断两字符串是否相等
54+
* Return whether string1 is equals to string2.
5555
*
56-
* @param a 待校验字符串 a
57-
* @param b 待校验字符串 b
58-
* @return {@code true}: 相等<br>{@code false}: 不相等
56+
* @param s1 The first string.
57+
* @param s2 The second string.
58+
* @return {@code true}: yes<br>{@code false}: no
5959
*/
60-
public static boolean equals(final CharSequence a, final CharSequence b) {
61-
if (a == b) return true;
60+
public static boolean equals(final CharSequence s1, final CharSequence s2) {
61+
if (s1 == s2) return true;
6262
int length;
63-
if (a != null && b != null && (length = a.length()) == b.length()) {
64-
if (a instanceof String && b instanceof String) {
65-
return a.equals(b);
63+
if (s1 != null && s2 != null && (length = s1.length()) == s2.length()) {
64+
if (s1 instanceof String && s2 instanceof String) {
65+
return s1.equals(s2);
6666
} else {
6767
for (int i = 0; i < length; i++) {
68-
if (a.charAt(i) != b.charAt(i)) return false;
68+
if (s1.charAt(i) != s2.charAt(i)) return false;
6969
}
7070
return true;
7171
}
@@ -74,63 +74,63 @@ public static boolean equals(final CharSequence a, final CharSequence b) {
7474
}
7575

7676
/**
77-
* 判断两字符串忽略大小写是否相等
77+
* Return whether string1 is equals to string2, ignoring case considerations..
7878
*
79-
* @param a 待校验字符串 a
80-
* @param b 待校验字符串 b
81-
* @return {@code true}: 相等<br>{@code false}: 不相等
79+
* @param s1 The first string.
80+
* @param s2 The second string.
81+
* @return {@code true}: yes<br>{@code false}: no
8282
*/
83-
public static boolean equalsIgnoreCase(final String a, final String b) {
84-
return a == null ? b == null : a.equalsIgnoreCase(b);
83+
public static boolean equalsIgnoreCase(final String s1, final String s2) {
84+
return s1 == null ? s2 == null : s1.equalsIgnoreCase(s2);
8585
}
8686

8787
/**
88-
* null 转为长度为 0 的字符串
88+
* Return {@code ""} if string equals null.
8989
*
90-
* @param s 待转字符串
91-
* @return s 为 null 转为长度为 0 字符串,否则不改变
90+
* @param s The string.
91+
* @return {@code ""} if string equals null
9292
*/
9393
public static String null2Length0(final String s) {
9494
return s == null ? "" : s;
9595
}
9696

9797
/**
98-
* 返回字符串长度
98+
* Return the length of string.
9999
*
100-
* @param s 字符串
101-
* @return null 返回 0,其他返回自身长度
100+
* @param s The string.
101+
* @return the length of string
102102
*/
103103
public static int length(final CharSequence s) {
104104
return s == null ? 0 : s.length();
105105
}
106106

107107
/**
108-
* 首字母大写
108+
* Set the first letter of string upper.
109109
*
110-
* @param s 待转字符串
111-
* @return 首字母大写字符串
110+
* @param s The string.
111+
* @return the string with first letter upper.
112112
*/
113113
public static String upperFirstLetter(final String s) {
114114
if (isEmpty(s) || !Character.isLowerCase(s.charAt(0))) return s;
115115
return String.valueOf((char) (s.charAt(0) - 32)) + s.substring(1);
116116
}
117117

118118
/**
119-
* 首字母小写
119+
* Set the first letter of string lower.
120120
*
121-
* @param s 待转字符串
122-
* @return 首字母小写字符串
121+
* @param s The string.
122+
* @return the string with first letter lower.
123123
*/
124124
public static String lowerFirstLetter(final String s) {
125125
if (isEmpty(s) || !Character.isUpperCase(s.charAt(0))) return s;
126126
return String.valueOf((char) (s.charAt(0) + 32)) + s.substring(1);
127127
}
128128

129129
/**
130-
* 反转字符串
130+
* Reverse the string.
131131
*
132-
* @param s 待反转字符串
133-
* @return 反转字符串
132+
* @param s The string.
133+
* @return the reverse string.
134134
*/
135135
public static String reverse(final String s) {
136136
int len = length(s);
@@ -147,10 +147,10 @@ public static String reverse(final String s) {
147147
}
148148

149149
/**
150-
* 转化为半角字符
150+
* Convert string to DBC.
151151
*
152-
* @param s 待转字符串
153-
* @return 半角字符串
152+
* @param s The string.
153+
* @return the DBC string
154154
*/
155155
public static String toDBC(final String s) {
156156
if (isEmpty(s)) return s;
@@ -168,17 +168,17 @@ public static String toDBC(final String s) {
168168
}
169169

170170
/**
171-
* 转化为全角字符
171+
* Convert string to SBC.
172172
*
173-
* @param s 待转字符串
174-
* @return 全角字符串
173+
* @param s The string.
174+
* @return the SBC string
175175
*/
176176
public static String toSBC(final String s) {
177177
if (isEmpty(s)) return s;
178178
char[] chars = s.toCharArray();
179179
for (int i = 0, len = chars.length; i < len; i++) {
180180
if (chars[i] == ' ') {
181-
chars[i] = (char) 12288;
181+
chars[i] = (char) 12288;
182182
} else if (33 <= chars[i] && chars[i] <= 126) {
183183
chars[i] = (char) (chars[i] + 65248);
184184
} else {

0 commit comments

Comments
 (0)