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

cc.owoo.godpen.content.html.extract.ExtractStringBuilder Maven / Gradle / Ivy

package cc.owoo.godpen.content.html.extract;

import cc.owoo.godpen.content.json.Json;

/**
 * 提取器序列化字符串
 * Created by nimensei
 * 2022-10-21 上午 01:16
 */
public class ExtractStringBuilder {
    private final StringBuilder string = new StringBuilder();// 字符串

    /**
     * 添加数字
     *
     * @param number 数字
     */
    public ExtractStringBuilder append(int number) {
        return append(String.valueOf(number));
    }

    /**
     * 添加数字
     *
     * @param number 数字
     */
    public ExtractStringBuilder append(double number) {
        return append(String.valueOf(number));
    }

    /**
     * 添加字符
     *
     * @param c 字符
     */
    public ExtractStringBuilder append(char c) {
        string.append(c);
        return this;
    }

    /**
     * 添加字符串
     *
     * @param s 字符串
     */
    public ExtractStringBuilder append(String s) {
        string.append(s);
        return this;
    }

    /**
     * 添加字符串
     *
     * @param s 字符串
     */
    public ExtractStringBuilder append(StringBuilder s) {
        string.append(s);
        return this;
    }

    /**
     * 添加文本,如果出现特殊字符,则使用字符串表达式
     *
     * @param s 字符串
     */
    public ExtractStringBuilder appendText(String s) {
        if (s.indexOf('\'') != -1 ||
                s.indexOf('"') != -1 ||
                s.indexOf('(') != -1 ||
                s.indexOf(')') != -1 ||
                s.indexOf('{') != -1 ||
                s.indexOf('}') != -1 ||
                s.indexOf(';') != -1 ||
                s.contains("->") ||
                s.contains("="))
            string.append(Json.stringify(s));
        else
            string.append(s);
        return this;
    }

    /**
     * 获取字符串长度
     *
     * @return 字符串长度
     */
    public int length() {
        return string.length();
    }

    @Override
    public String toString() {
        return string.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy