Kaynağa Gözat

删除多余的工具类

RuoYi 3 yıl önce
ebeveyn
işleme
2051819d2d

+ 0 - 164
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ReUtil.java

@@ -1,164 +0,0 @@
1
-package com.ruoyi.common.core.utils;
2
-
3
-import java.util.Arrays;
4
-import java.util.Collection;
5
-import java.util.HashSet;
6
-import java.util.Set;
7
-import java.util.regex.Matcher;
8
-import java.util.regex.Pattern;
9
-
10
-import com.ruoyi.common.core.text.Convert;
11
-import com.ruoyi.common.core.utils.StringUtils;
12
-
13
-public class ReUtil
14
-{
15
-    public final static Pattern GROUP_VAR = Pattern.compile("\\$(\\d+)");
16
-
17
-    /**
18
-     * 正则中需要被转义的关键字
19
-     */
20
-    public final static Set<Character> RE_KEYS = new HashSet<>(
21
-            Arrays.asList('$', '(', ')', '*', '+', '.', '[', ']', '?', '\\', '^', '{', '}', '|'));
22
-
23
-    /**
24
-     * 正则替换指定值<br>
25
-     * 通过正则查找到字符串,然后把匹配到的字符串加入到replacementTemplate中,$1表示分组1的字符串
26
-     *
27
-     * <p>
28
-     * 例如:原字符串是:中文1234,我想把1234换成(1234),则可以:
29
-     *
30
-     * <pre>
31
-     * ReUtil.replaceAll("中文1234", "(\\d+)", "($1)"))
32
-     *
33
-     * 结果:中文(1234)
34
-     * </pre>
35
-     *
36
-     * @param content 文本
37
-     * @param regex 正则
38
-     * @param replacementTemplate 替换的文本模板,可以使用$1类似的变量提取正则匹配出的内容
39
-     * @return 处理后的文本
40
-     */
41
-    public static String replaceAll(CharSequence content, String regex, String replacementTemplate)
42
-    {
43
-        final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
44
-        return replaceAll(content, pattern, replacementTemplate);
45
-    }
46
-
47
-    /**
48
-     * 正则替换指定值<br>
49
-     * 通过正则查找到字符串,然后把匹配到的字符串加入到replacementTemplate中,$1表示分组1的字符串
50
-     *
51
-     * @param content 文本
52
-     * @param pattern {@link Pattern}
53
-     * @param replacementTemplate 替换的文本模板,可以使用$1类似的变量提取正则匹配出的内容
54
-     * @return 处理后的文本
55
-     * @since 3.0.4
56
-     */
57
-    public static String replaceAll(CharSequence content, Pattern pattern, String replacementTemplate)
58
-    {
59
-        if (StringUtils.isEmpty(content))
60
-        {
61
-            return StringUtils.EMPTY;
62
-        }
63
-
64
-        final Matcher matcher = pattern.matcher(content);
65
-        boolean result = matcher.find();
66
-        if (result)
67
-        {
68
-            final Set<String> varNums = findAll(GROUP_VAR, replacementTemplate, 1, new HashSet<>());
69
-            final StringBuffer sb = new StringBuffer();
70
-            do
71
-            {
72
-                String replacement = replacementTemplate;
73
-                for (String var : varNums)
74
-                {
75
-                    int group = Integer.parseInt(var);
76
-                    replacement = replacement.replace("$" + var, matcher.group(group));
77
-                }
78
-                matcher.appendReplacement(sb, escape(replacement));
79
-                result = matcher.find();
80
-            }
81
-            while (result);
82
-            matcher.appendTail(sb);
83
-            return sb.toString();
84
-        }
85
-        return Convert.toStr(content);
86
-    }
87
- 
88
-    /**
89
-     * 取得内容中匹配的所有结果
90
-     *
91
-     * @param <T> 集合类型
92
-     * @param pattern 编译后的正则模式
93
-     * @param content 被查找的内容
94
-     * @param group 正则的分组
95
-     * @param collection 返回的集合类型
96
-     * @return 结果集
97
-     */
98
-    public static <T extends Collection<String>> T findAll(Pattern pattern, CharSequence content, int group,
99
-            T collection)
100
-    {
101
-        if (null == pattern || null == content)
102
-        {
103
-            return null;
104
-        }
105
-
106
-        if (null == collection)
107
-        {
108
-            throw new NullPointerException("Null collection param provided!");
109
-        }
110
-
111
-        final Matcher matcher = pattern.matcher(content);
112
-        while (matcher.find())
113
-        {
114
-            collection.add(matcher.group(group));
115
-        }
116
-        return collection;
117
-    }
118
-
119
-    /**
120
-     * 转义字符,将正则的关键字转义
121
-     *
122
-     * @param c 字符
123
-     * @return 转义后的文本
124
-     */
125
-    public static String escape(char c)
126
-    {
127
-        final StringBuilder builder = new StringBuilder();
128
-        if (RE_KEYS.contains(c))
129
-        {
130
-            builder.append('\\');
131
-        }
132
-        builder.append(c);
133
-        return builder.toString();
134
-    }
135
-
136
-    /**
137
-     * 转义字符串,将正则的关键字转义
138
-     *
139
-     * @param content 文本
140
-     * @return 转义后的文本
141
-     */
142
-    public static String escape(CharSequence content)
143
-    {
144
-        if (StringUtils.isBlank(content))
145
-        {
146
-            return StringUtils.EMPTY;
147
-        }
148
-
149
-        final StringBuilder builder = new StringBuilder();
150
-        int len = content.length();
151
-        char current;
152
-        for (int i = 0; i < len; i++)
153
-        {
154
-            current = content.charAt(i);
155
-            if (RE_KEYS.contains(current))
156
-            {
157
-                builder.append('\\');
158
-            }
159
-            builder.append(current);
160
-        }
161
-        return builder.toString();
162
-    }
163
-
164
-}