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

top.gotoeasy.framework.spring.aop.util.StringUtil Maven / Gradle / Ivy

Go to download

基于JavaCompiler的继承方式AOP实现,在性能优良的基础上,提供更多的简易性,2.x.x版本集成使用Spring容器

The newest version!
package top.gotoeasy.framework.spring.aop.util;

import java.util.regex.Pattern;

import org.springframework.util.StringUtils;

/**
 * StringUtil
 * 
 * @since 2018/01
 * @author 青松
 */
public class StringUtil extends StringUtils {

    /**
     * 通配符"*"匹配
     * 

* 通配符: 星号"*"表示任意个任意字符 *

* * @param pattern 匹配模型(星号"*"表示任意个任意字符) * @param source 待匹配目标字符串 * @return true:匹配/false:不匹配 (任意参数为空时都固定返回false) */ public static boolean wildcardsMatch(String pattern, String source) { if (isEmpty(pattern) || isEmpty(source)) { return false; } String regStrs = "$^[]{}()|.\\"; StringBuilder buf = new StringBuilder(); buf.append("^"); char ch; for (int i = 0; i < pattern.length(); i++) { ch = pattern.charAt(i); if (ch == '*') { buf.append(".*"); } else if (regStrs.indexOf(ch) >= 0) { buf.append("\\").append(ch); } else { buf.append(ch); } } buf.append("$"); return Pattern.compile(buf.toString()).matcher(source).matches(); } // public static void main(String... args) { // String pattern = "* logout(*)"; // String source = "public Result logout(HttpServletRequest request,HttpServletResponse response)"; // System.err.println(wildcardsMatch(pattern, source)); // } }