com.taotao.boot.sensitive.wordother.utils.NumUtils Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.taotao.boot.sensitive.wordother.utils;
import com.google.common.collect.Maps;
import com.taotao.boot.common.utils.lang.ObjectUtils;
import com.taotao.boot.common.utils.lang.StringUtils;
import com.taotao.boot.sensitive.wordother.api.IWordContext;
import com.taotao.boot.sensitive.wordother.constant.enums.ValidModeEnum;
import java.util.Map;
public final class NumUtils {
private NumUtils() {}
private static final String NUM_ONE = "⓪0零º₀⓿○"
+ "123456789"
+ "一二三四五六七八九"
+ "壹贰叁肆伍陆柒捌玖"
+ "¹²³⁴⁵⁶⁷⁸⁹"
+ "₁₂₃₄₅₆₇₈₉"
+ "①②③④⑤⑥⑦⑧⑨"
+ "⑴⑵⑶⑷⑸⑹⑺⑻⑼"
+ "⒈⒉⒊⒋⒌⒍⒎⒏⒐"
+ "❶❷❸❹❺❻❼❽❾"
+ "➀➁➂➃➄➅➆➇➈"
+ "➊➋➌➍➎➏➐➑➒"
+ "㈠㈡㈢㈣㈤㈥㈦㈧㈨"
+ "⓵⓶⓷⓸⓹⓺⓻⓼⓽"
+ "㊀㊁㊂㊃㊄㊅㊆㊇㊈"
+ "ⅰⅱⅲⅳⅴⅵⅶⅷⅸ"
+ "ⅠⅡⅢⅣⅤⅥⅦⅧⅨ";
private static final String NUM_TWO = "0000000"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789"
+ "123456789";
/** 英文字母 map */
private static final Map NUMBER_MAP = Maps.newHashMap();
static {
final int size = NUM_ONE.length();
for (int i = 0; i < size; i++) {
NUMBER_MAP.put(NUM_ONE.charAt(i), NUM_TWO.charAt(i));
}
}
/**
* 映射后的 char
*
* @param character 待转换的 char
* @return 结果
*/
public static Character getMappingChar(final Character character) {
final Character mapChar = NUMBER_MAP.get(character);
if (ObjectUtils.isNotNull(mapChar)) {
return mapChar;
}
return character;
}
public static String getMappingString(final String string) {
if (StringUtils.isEmpty(string)) {
return string;
}
char[] chars = string.toCharArray();
StringBuilder stringBuilder = new StringBuilder(chars.length);
for (char c : chars) {
char mapChar = getMappingChar(c);
// TODO: stop word 的处理
stringBuilder.append(mapChar);
}
return stringBuilder.toString();
}
/**
* 检查敏感词数量
*
* (1)如果未命中敏感词,直接返回 0 (2)命中敏感词,则返回敏感词的长度。
*
*
ps: 这里结果进行优化, 1. 是否包含敏感词。 2. 敏感词的长度 3. 正常走过字段的长度(便于后期替换优化,避免不必要的循环重复)
*
* @param txt 文本信息
* @param beginIndex 开始下标
* @param validModeEnum 验证模式
* @param context 执行上下文
* @return 敏感数字对应的长度
*/
private int getSensitiveNumber(
final String txt, final int beginIndex, final ValidModeEnum validModeEnum, final IWordContext context) {
return 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy