All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taotao.boot.sensitive.wordother.utils.InnerFormatUtils Maven / Gradle / Ivy

/*
 * 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.taotao.boot.common.support.instance.impl.Instances;
import com.taotao.boot.common.utils.lang.StringUtils;
import com.taotao.boot.sensitive.wordother.api.ICharFormat;
import com.taotao.boot.sensitive.wordother.api.IWordContext;
import com.taotao.boot.sensitive.wordother.support.format.CharFormatChain;

/** 内部格式化工具类 */
public final class InnerFormatUtils {

    private InnerFormatUtils() {}

    /**
     * 格式化
     *
     * @param original 原始
     * @param context 上下文
     * @return 结果
     */
    public static String format(String original, IWordContext context) {
        if (StringUtils.isEmpty(original)) {
            return original;
        }

        StringBuilder stringBuilder = new StringBuilder();
        ICharFormat charFormat = Instances.singleton(CharFormatChain.class);
        char[] chars = original.toCharArray();
        for (char c : chars) {
            char cf = charFormat.format(c, context);
            stringBuilder.append(cf);
        }

        return stringBuilder.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy