mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
fixed - Unicode encoding , exclude base latin letter.
This commit is contained in:
parent
bf08ab3110
commit
62398e1bc2
@ -33,16 +33,26 @@ public final class NacosConfigUtils {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
char[] chars = configValue.toCharArray();
|
char[] chars = configValue.toCharArray();
|
||||||
for (char aChar : chars) {
|
for (char aChar : chars) {
|
||||||
if (isChinese(aChar)) {
|
if (isBaseLetter(aChar)) {
|
||||||
sb.append("\\u").append(Integer.toHexString(aChar));
|
sb.append(aChar);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb.append(aChar);
|
sb.append(String.format("\\u%04x", (int) aChar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* char is base latin or whitespace?
|
||||||
|
* @param ch a character
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
public static boolean isBaseLetter(char ch) {
|
||||||
|
Character.UnicodeBlock ub = Character.UnicodeBlock.of(ch);
|
||||||
|
return ub == Character.UnicodeBlock.BASIC_LATIN || Character.isWhitespace(ch);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* char is chinese?
|
* char is chinese?
|
||||||
* @param c a character
|
* @param c a character
|
||||||
|
Loading…
x
Reference in New Issue
Block a user