增加双字节判断

pull/330/head
AriaLyy 7 years ago
parent 17c0caedd9
commit f546ebb7cb
  1. 6
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java

@ -74,7 +74,7 @@ public class CommonUtil {
* @return 转换后的地址 * @return 转换后的地址
*/ */
public static String convertUrl(String url) { public static String convertUrl(String url) {
if (hasChineseCharacter(url)) { if (hasDoubleCharacter(url)) {
//匹配双字节字符(包括汉字在内) //匹配双字节字符(包括汉字在内)
String regex = "[^\\x00-\\xff]"; String regex = "[^\\x00-\\xff]";
Pattern p = Pattern.compile(regex); Pattern p = Pattern.compile(regex);
@ -100,10 +100,10 @@ public class CommonUtil {
* @param chineseStr 需要进行判断的字符串 * @param chineseStr 需要进行判断的字符串
* @return {@code true}有双字节字符{@code false} 无双字节字符 * @return {@code true}有双字节字符{@code false} 无双字节字符
*/ */
public static boolean hasChineseCharacter(String chineseStr) { public static boolean hasDoubleCharacter(String chineseStr) {
char[] charArray = chineseStr.toCharArray(); char[] charArray = chineseStr.toCharArray();
for (char aCharArray : charArray) { for (char aCharArray : charArray) {
if (aCharArray <= 0xff) { if ((aCharArray >= 0x0391) && (aCharArray <= 0xFFE5)) {
return true; return true;
} }
} }

Loading…
Cancel
Save