public Pattern apply(String pattern) { try { PatternCompiler pc = new Perl5Compiler(); return pc.compile(pattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); } catch (MalformedPatternException e) { throw new RuntimeException(e); } } });
private static boolean isDml(String queryString, String pattern) { Perl5Matcher matcher = new Perl5Matcher(); if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) { return true; } else { return false; } }
public String findFirst(String originalStr, String regex) { if (StringUtils.isBlank(originalStr) || StringUtils.isBlank(regex)) { return StringUtils.EMPTY; } PatternMatcher matcher = new Perl5Matcher(); if (matcher.contains(originalStr, patterns.get(regex))) { return StringUtils.trimToEmpty(matcher.getMatch().group(0)); } return StringUtils.EMPTY; } }
private static DdlResult parseDdl(String queryString, String schmeaName, String pattern, int index) { Perl5Matcher matcher = new Perl5Matcher(); if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) { DdlResult result = parseTableName(matcher.getMatch().group(index), schmeaName); return result != null ? result : new DdlResult(schmeaName); // 无法解析时,直接返回schmea,进行兼容处理 } return null; }
private void setupMatcher() { if (_compiler == null) _compiler = new Perl5Compiler(); if (_matcher == null) _matcher = new Perl5Matcher(); }
/** * 编译对应的pattern,返回oro的Pattern对象 */ private Pattern[] compilePatterns(String[] source) { Perl5Compiler compiler = new Perl5Compiler(); Pattern[] destination = new Pattern[source.length]; for (int i = 0; i < source.length; i++) { try { destination[i] = compiler.compile(source[i], Perl5Compiler.READ_ONLY_MASK); } catch (MalformedPatternException ex) { throw new AsyncLoadException(ex.getMessage()); } } return destination; }
private boolean matchesRegExp(String string) { PatternMatcher matcher = new Perl5Matcher(); return matcher.matches(string, pattern); }
/** * Constructor */ public URLPatternFactory() { compiler = new Perl5Compiler(); }
@Override protected Perl5Matcher initialValue() { return new Perl5Matcher(); } };
/** * 优先采取excludePattern * * @param signatureString * @return */ private boolean matchesExclusionFirst(String signatureString) { // 优先采取excludePattern boolean excluded = false; for (int i = 0; i < this.compiledExclusionPatterns.length; i++) { excluded |= this.matcher.matches(signatureString, this.compiledExclusionPatterns[i]); } return !excluded; }
/** * 取得并复位匹配的输入值. 每次匹配动作完成后, 必须调用此方法才可进行第二次匹配. * * @return input 匹配的输入值 */ public PatternMatcherInput getInputReset() { input.setCurrentOffset(input.getBeginOffset()); return input; }
/** * 实现<code>MatchResult</code>接口, 取得指定group末尾相对于整个匹配的位移量. * * @param group group号, 0代表整个匹配 * @return 指定group末尾相对于整个匹配的位移量, 如果指定group不存在或未匹配, 则返回-1, 被匹配的字符串长度为0, * 则返回起始位移量 */ public int end(int group) { return result == null ? -1 : result.end(group); }
/** * 实现<code>MatchResult</code>接口, 取得匹配长度. * * @return 匹配的长度 */ public int length() { return result == null ? 0 : result.length(); }
/** * 实现<code>MatchResult</code>接口, 取得指定group相对于整个匹配的位移量. * * @param group group号, 0代表整个匹配 * @return 指定group相对于整个匹配的位移量, 注意如果被匹配的字符串长度为0, 且位于字符串的末尾, 则位移量等于字符串的长度. */ public int begin(int group) { return result == null ? -1 : result.begin(group); }
private static DdlResult parseRename(String queryString, String schmeaName, String pattern) { Perl5Matcher matcher = new Perl5Matcher(); if (matcher.matches(queryString, PatternUtils.getPattern(pattern))) { DdlResult orign = parseTableName(matcher.getMatch().group(1), schmeaName); DdlResult target = parseTableName(matcher.getMatch().group(2), schmeaName); if (orign != null && target != null) { return new DdlResult(target.getSchemaName(), target.getTableName(), orign.getSchemaName(), orign.getTableName()); } } return null; }
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) { String pattern = FunctionUtils.getStringValue(arg1, env); String text = FunctionUtils.getStringValue(arg2, env); Perl5Matcher matcher = new Perl5Matcher(); boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern)); return AviatorBoolean.valueOf(isMatch); }
public Pattern apply(String pattern) { try { PatternCompiler pc = new Perl5Compiler(); return pc.compile(pattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK); } catch (MalformedPatternException e) { throw new RuntimeException("Regex failed!", e); } } });
public Perl5Compiler getCompiler() { if( compiler == null) compiler = new Perl5Compiler(); return compiler; }
/** * 优先采取pattern * * @param signatureString * @return */ private boolean matchesFirst(String signatureString) { // 优先采取pattern for (int i = 0; i < this.compiledPatterns.length; i++) { boolean matched = this.matcher.matches(signatureString, this.compiledPatterns[i]); if (matched) {// 如果匹配,再进行excludePattern过滤 for (int j = 0; j < this.compiledExclusionPatterns.length; j++) { boolean excluded = this.matcher.matches(signatureString, this.compiledExclusionPatterns[j]); if (excluded) { return false; } } return true; } } return false; }
private static DdlResult parseTableName(String matchString, String schmeaName) { Perl5Matcher tableMatcher = new Perl5Matcher(); matchString = matchString + " "; if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) { String tableString = tableMatcher.getMatch().group(3); if (StringUtils.isEmpty(tableString)) { return null; } tableString = StringUtils.removeEnd(tableString, ";"); tableString = StringUtils.removeEnd(tableString, "("); tableString = StringUtils.trim(tableString); // 特殊处理引号` tableString = removeEscape(tableString); // 处理schema.table的写法 String names[] = StringUtils.split(tableString, "."); if (names.length == 0) { return null; } if (names != null && names.length > 1) { return new DdlResult(removeEscape(names[0]), removeEscape(names[1])); } else { return new DdlResult(schmeaName, removeEscape(names[0])); } } return null; }