kongzy
2024-09-14 f0f00e9ba8a755e4317e029d73b69a92ad9f9df1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.gkhy.exam.common.utils;
 
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.util.AntPathMatcher;
 
import java.util.List;
 
import static org.apache.commons.lang3.StringUtils.startsWithAny;
 
public class StringUtils extends StrUtil {
 
    /**
     * 是否为http(s)://开头
     *
     * @param link 链接
     * @return 结果
     */
    public static boolean ishttp(String link)
    {
        /**
         * http请求
         */
        String HTTP = "http://";
 
        /**
         * https请求
         */
        String HTTPS = "https://";
        return startsWithAny(link, HTTP,HTTPS);
    }
 
    public static String capitalize(final String str){
        return org.apache.commons.lang3.StringUtils.capitalize(str);
    }
 
    public static String replaceEach(final String text, final String[] searchList, final String[] replacementList){
        return org.apache.commons.lang3.StringUtils.replaceEach(text, searchList, replacementList);
    }
 
 
    /**
     * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
     *
     * @param str 指定字符串
     * @param strs 需要检查的字符串数组
     * @return 是否匹配
     */
    public static boolean matches(String str, List<String> strs)
    {
        if (isBlank(str) || ObjectUtil.isEmpty(strs))
        {
            return false;
        }
        for (String pattern : strs)
        {
            if (isMatch(pattern, str))
            {
                return true;
            }
        }
        return false;
    }
 
    /**
     * 判断url是否与规则配置:
     * ? 表示单个字符;
     * * 表示一层路径内的任意字符串,不可跨层级;
     * ** 表示任意层路径;
     *
     * @param pattern 匹配规则
     * @param url 需要匹配的url
     * @return
     */
    public static boolean isMatch(String pattern, String url)
    {
        AntPathMatcher matcher = new AntPathMatcher();
        return matcher.match(pattern, url);
    }
 
}