CharacterUtils-字符集处理工具类
作用
本工具类主要提供常用的字符集处理的方法
API列表
/**
* 过滤GB2312内不支持的字符集(不含日韩俄字符)的方法
*
* @param origin 需要处理的原始字符串
* @param placeholder 自定义占位符
* @return 返回处理后的字符串
*/
public static String filterContentForGB2312(String origin, String placeholder) {
// to do sth.
}
/**
* 过滤GB2312内不支持的字符集(不含日韩俄字符)的方法
*
* @param origin 需要处理的原始字符串
* @return 返回处理后的字符串
*/
public static String filterContentForGB2312(String origin) {
// to do sth.
}
/**
* 检查指定字符是否在支持的字符范围内的方法
*
* @param c 待检查的字符
* @return 返回检查结果(true:支持,false:不支持)
*/
public static boolean isSupportedCharacter(char c) {
// to do sth.
}
/**
* 检查指定字符是否在支持的字符范围内的方法
*
* @param c 待检查的字符
* @param scripts 待指定的字符集列表
* @return 返回检查结果(true:支持,false:不支持)
*/
public static boolean isSupportedCharacter(char c, Character.UnicodeScript... scripts) {
// to do sth.
}
/**
* 检查指定字符是否在支持的字符范围内的方法
*
* @param c 待检查的字符
* @param unicodeEnums 待指定的字符集列表
* @return 返回检查结果(true:支持,false:不支持)
*/
public static boolean isSupportedCharacter(char c, UnicodeEnum... unicodeEnums) {
// to do sth.
}
/**
* 执行文本压缩的方法
*
* @param originString 原始文本
* @return 返回压缩后的文本
*/
@Nullable
public static String compress(@NonNull String originString) {
// to do sth.
}
/**
* 执行文本解压缩的方法
*
* @param compressedString 压缩文本
* @return 返回解压缩后的文本
*/
public static String decompress(@NonNull String compressedString) {
// to do sth.
}
/**
* 全角转换成半角
*
* @param input 原始字符串
* @return 返回转换后的字符串
*/
public static String convertFull2Half(String input) {
// to do sth.
}
/**
* 半角转全角
*
* @param input 原始字符串
* @return 返回转换后的字符串
*/
public static String convertHalf2Full(String input) {
// to do sth.
}
用法
静态工具类方法,直接使用即可。
演示
String originText = "大文本";
var compressText = CharacterUtils.compress(originText);
if (compressText == null) {
System.err.println("压缩失败!");
return;
}
System.err.println(STR."压缩文本长度:\{compressText.length()}");
System.out.println(STR."压缩文本内容:\{compressText}");
var uncompress = CharacterUtils.decompress(compressText);
System.out.println(STR."解压缩文本内容:\{uncompress}");