From 2f3949d732872ee9281cb6f1bc15dc3968bf418f Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Thu, 27 May 2021 09:46:19 +0800
Subject: [PATCH] 升级Spring Cloud相关组件到最新版

---
 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java |  130 ++++++++++++------------------------------
 1 files changed, 38 insertions(+), 92 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java
index e0bc15a..b549d60 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java
@@ -3,6 +3,7 @@
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import org.springframework.util.AntPathMatcher;
 import com.ruoyi.common.core.text.StrFormatter;
 
 /**
@@ -17,9 +18,6 @@
 
     /** 下划线 */
     private static final char SEPARATOR = '_';
-
-    /** 星号 */
-    private static final String START = "*";
 
     /**
      * 获取参数不为空值
@@ -239,6 +237,30 @@
     }
 
     /**
+     * 判断是否为空,并且不是空白字符
+     * 
+     * @param str 要判断的value
+     * @return 结果
+     */
+    public static boolean hasText(String str)
+    {
+        return (str != null && !str.isEmpty() && containsText(str));
+    }
+
+    private static boolean containsText(CharSequence str)
+    {
+        int strLen = str.length();
+        for (int i = 0; i < strLen; i++)
+        {
+            if (!Character.isWhitespace(str.charAt(i)))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
      * 格式化文本, {} 表示占位符<br>
      * 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
      * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
@@ -261,7 +283,7 @@
     }
 
     /**
-     * 下划线转驼峰命名
+     * 驼峰转下划线命名
      */
     public static String toUnderScoreCase(String str)
     {
@@ -413,9 +435,9 @@
         {
             return false;
         }
-        for (String testStr : strs)
+        for (String pattern : strs)
         {
-            if (matches(str, testStr))
+            if (isMatch(pattern, str))
             {
                 return true;
             }
@@ -424,95 +446,19 @@
     }
 
     /**
-     * 查找指定字符串是否匹配指定字符串数组中的任意一个字符串
+     * 判断url是否与规则配置: 
+     * ? 表示单个字符; 
+     * * 表示一层路径内的任意字符串,不可跨层级; 
+     * ** 表示任意层路径;
      * 
-     * @param str 指定字符串
-     * @param strs 需要检查的字符串数组
-     * @return 是否匹配
+     * @param pattern 匹配规则
+     * @param url 需要匹配的url
+     * @return
      */
-    public static boolean matches(String str, String... strs)
+    public static boolean isMatch(String pattern, String url)
     {
-        if (isEmpty(str) || isEmpty(strs))
-        {
-            return false;
-        }
-        for (String testStr : strs)
-        {
-            if (matches(str, testStr))
-            {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * 查找指定字符串是否匹配
-     * 
-     * @param str 指定字符串
-     * @param pattern 需要检查的字符串
-     * @return 是否匹配
-     */
-    public static boolean matches(String str, String pattern)
-    {
-        if (isEmpty(pattern) || isEmpty(str))
-        {
-            return false;
-        }
-
-        pattern = pattern.replaceAll("\\s*", ""); // 替换空格
-        int beginOffset = 0; // pattern截取开始位置
-        int formerStarOffset = -1; // 前星号的偏移位置
-        int latterStarOffset = -1; // 后星号的偏移位置
-
-        String remainingURI = str;
-        String prefixPattern = "";
-        String suffixPattern = "";
-
-        boolean result = false;
-        do
-        {
-            formerStarOffset = indexOf(pattern, START, beginOffset);
-            prefixPattern = substring(pattern, beginOffset, formerStarOffset > -1 ? formerStarOffset : pattern.length());
-
-            // 匹配前缀Pattern
-            result = remainingURI.contains(prefixPattern);
-            // 已经没有星号,直接返回
-            if (formerStarOffset == -1)
-            {
-                return result;
-            }
-
-            // 匹配失败,直接返回
-            if (!result)
-                return false;
-
-            if (!isEmpty(prefixPattern))
-            {
-                remainingURI = substringAfter(str, prefixPattern);
-            }
-
-            // 匹配后缀Pattern
-            latterStarOffset = indexOf(pattern, START, formerStarOffset + 1);
-            suffixPattern = substring(pattern, formerStarOffset + 1, latterStarOffset > -1 ? latterStarOffset : pattern.length());
-
-            result = remainingURI.contains(suffixPattern);
-            // 匹配失败,直接返回
-            if (!result)
-                return false;
-
-            if (!isEmpty(suffixPattern))
-            {
-                remainingURI = substringAfter(str, suffixPattern);
-            }
-
-            // 移动指针
-            beginOffset = latterStarOffset + 1;
-
-        }
-        while (!isEmpty(suffixPattern) && !isEmpty(remainingURI));
-
-        return true;
+        AntPathMatcher matcher = new AntPathMatcher();
+        return matcher.match(pattern, url);
     }
 
     @SuppressWarnings("unchecked")

--
Gitblit v1.9.3