當前位置: 首頁>>代碼示例>>Java>>正文


Java Perl5Compiler類代碼示例

本文整理匯總了Java中org.apache.oro.text.regex.Perl5Compiler的典型用法代碼示例。如果您正苦於以下問題:Java Perl5Compiler類的具體用法?Java Perl5Compiler怎麽用?Java Perl5Compiler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Perl5Compiler類屬於org.apache.oro.text.regex包,在下文中一共展示了Perl5Compiler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convertStringToPattern

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * 把字符串轉成Pattern和UrlType
 * 
 * @param perl5RegExp
 * @return
 */
private URLPatternHolder convertStringToPattern(String line) {
    URLPatternHolder holder = new URLPatternHolder();
    Pattern compiledPattern;
    Perl5Compiler compiler = new Perl5Compiler();
    String perl5RegExp = line;
    try {
        compiledPattern = compiler.compile(perl5RegExp, Perl5Compiler.READ_ONLY_MASK);
        holder.setCompiledPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + perl5RegExp);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Added regular expression: " + compiledPattern.getPattern().toString());
    }
    return holder;
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:24,代碼來源:URLProtectedEditor.java

示例2: createOrGetPerl5CompiledPattern

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * Compiles and caches a Perl5 regexp pattern for the given string pattern.
 * This would be of no benefits (and may bloat memory usage) if stringPattern is never the same.
 * @param stringPattern a Perl5 pattern string
 * @param caseSensitive case sensitive true/false
 * @return a <code>Pattern</code> instance for the given string pattern
 * @throws MalformedPatternException
 */

public static Pattern createOrGetPerl5CompiledPattern(String stringPattern, boolean caseSensitive) throws MalformedPatternException {
    Pattern pattern = compiledPerl5Patterns.get(stringPattern);
    if (pattern == null) {
        Perl5Compiler compiler = new Perl5Compiler();
        if (caseSensitive) {
            pattern = compiler.compile(stringPattern, Perl5Compiler.READ_ONLY_MASK); // READ_ONLY_MASK guarantees immutability
        } else {
            pattern = compiler.compile(stringPattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
        }
        pattern = compiledPerl5Patterns.putIfAbsentAndGet(stringPattern, pattern);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Compiled and cached the pattern: '" + stringPattern, module);
        }
    }
    return pattern;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:26,代碼來源:PatternFactory.java

示例3: WildCardFilter

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * @param wildcard
 * @throws MalformedPatternException
 */
public WildCardFilter(String wildcard,boolean ignoreCase) throws MalformedPatternException {
    this.wildcard=wildcard;
    this.ignoreCase=ignoreCase;
    StringBuffer sb = new StringBuffer(wildcard.length());
    int len=wildcard.length();
    
    for(int i=0;i<len;i++) {
        char c = wildcard.charAt(i);
        if(c == '*')sb.append(".*");
        else if(c == '?') sb.append('.');
        else if(specials.indexOf(c)!=-1)sb.append('\\').append(c);
        else sb.append(c);
    }
    pattern=new Perl5Compiler().compile(ignoreCase?sb.toString().toLowerCase():sb.toString());
}
 
開發者ID:lucee,項目名稱:extension-mongodb,代碼行數:20,代碼來源:WildCardFilter.java

示例4: fetch

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * 提取子串
 * @param src	輸入字符串
 * @param regx	表達式
 * @return
 */
public List<List<String>> fetch(String src, String regx){
	List<List<String>> list = new ArrayList<List<String>>();
	try{
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
		PatternMatcher matcher = new Perl5Matcher();
		PatternMatcherInput input = new PatternMatcherInput(src);
		while(matcher.matches(input, pattern)){
			MatchResult matchResult = matcher.getMatch();
			int groups = matchResult.groups();
			List<String> item = new ArrayList<String>();
			for(int i=0; i<=groups; i++){
				item.add(matchResult.group(i));
			}
			list.add(item);
		}
	}catch(Exception e){
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return list;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:29,代碼來源:RegularMatch.java

示例5: indexOf

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * 字符串下標 regx在src中首次出現的位置
 * @param src   
 * @param regx  
 * @param idx   有效開始位置
 * @return
 * @throws Exception
 */
public static int indexOf(String src, String regx, int begin){
	int idx = -1;
	try{
		PatternCompiler patternCompiler = new Perl5Compiler();
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
		PatternMatcher matcher = new Perl5Matcher();
		PatternMatcherInput input = new PatternMatcherInput(src);
		
		while(matcher.contains(input, pattern)){
			MatchResult matchResult = matcher.getMatch();
			int tmp = matchResult.beginOffset(0);
			if(tmp >= begin){//匹配位置從begin開始
				idx = tmp;
				break;
			}
		}
	}catch(Exception e){
		log.error("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return idx;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:33,代碼來源:RegularUtil.java

示例6: fetch

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * 提取子串
 * @param src	輸入字符串
 * @param regx	表達式
 * @return
 */
public List<List<String>> fetch(String src, String regx){
	List<List<String>> list = new ArrayList<List<String>>();
	try{
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
		PatternMatcher matcher = new Perl5Matcher();
		PatternMatcherInput input = new PatternMatcherInput(src);
		while(matcher.matchesPrefix(input, pattern)){
			MatchResult matchResult = matcher.getMatch();
			int groups = matchResult.groups();
			List<String> item = new ArrayList<String>();
			for(int i=0; i<=groups; i++){
				item.add(matchResult.group(i));
			}
			list.add(item);
		}
	}catch(Exception e){
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return list;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:29,代碼來源:RegularMatchPrefix.java

示例7: fetch

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * 提取子串
 * @param src	輸入字符串
 * @param regx	表達式
 * @return
 */
public List<List<String>> fetch(String src, String regx){
	List<List<String>> list = new ArrayList<List<String>>();
	try{
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
		PatternMatcher matcher = new Perl5Matcher();
		PatternMatcherInput input = new PatternMatcherInput(src);
		while(matcher.contains(input, pattern)){
			MatchResult matchResult = matcher.getMatch();
			int groups = matchResult.groups();
			List<String> item = new ArrayList<String>();
			for(int i=0; i<groups; i++){
				item.add(matchResult.group(i));
			}
			list.add(item);
		}
	}catch(Exception e){
		log.error("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
		if(ConfigTable.isDebug()){
			e.printStackTrace();
		}
	}
	return list;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:30,代碼來源:RegularContain.java

示例8: fetch

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * 提取子串
 * @param src	輸入字符串
 * @param regx	表達式
 * @return
 */
public List<List<String>> fetch(String src, String regx){
	List<List<String>> list = new ArrayList<List<String>>();
	try{
		Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
		PatternMatcher matcher = new Perl5Matcher();
		PatternMatcherInput input = new PatternMatcherInput(src);
		while(matcher.contains(input, pattern)){
			MatchResult matchResult = matcher.getMatch();
			int groups = matchResult.groups();
			List<String> item = new ArrayList<String>();
			for(int i=0; i<groups; i++){
				item.add(matchResult.group(i));
			}
			list.add(item);
		}
	}catch(Exception e){
		log.error("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
	}
	return list;
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:27,代碼來源:RegxpContain.java

示例9: getTaskPattern

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
@Nullable
private Pattern getTaskPattern(String pattern) {
  if (!Comparing.strEqual(pattern, myPattern)) {
    myCompiledPattern = null;
    myPattern = pattern;
  }
  if (myCompiledPattern == null) {
    final String regex = "^.*" + NameUtil.buildRegexp(pattern, 0, true, true);

    final Perl5Compiler compiler = new Perl5Compiler();
    try {
      myCompiledPattern = compiler.compile(regex);
    }
    catch (MalformedPatternException ignored) {
    }
  }
  return myCompiledPattern;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:ListChooseByNameModel.java

示例10: matchesPatterns

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
private boolean matchesPatterns(String url, CollectionProperty patterns)
{
    for (JMeterProperty jMeterProperty : patterns)
    {
        String item = jMeterProperty.getStringValue();
        try
        {
            Pattern pattern = JMeterUtils.getPatternCache().getPattern(item,
                    Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
            if (JMeterUtils.getMatcher().matches(url, pattern))
            {
                return true;
            }
        }
        catch (MalformedCachePatternException e)
        {
            LOG.warn("Skipped invalid pattern: " + item, e);
        }
    }
    return false;
}
 
開發者ID:d0k1,項目名稱:jsflight,代碼行數:22,代碼來源:JMeterProxyControl.java

示例11: WildCardFilter

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * @param wildcard
 * @throws MalformedPatternException
 */
public WildCardFilter(String wildcard,boolean ignoreCase) throws MalformedPatternException {
    this.wildcard=wildcard;
    StringBuilder sb = new StringBuilder(wildcard.length());
    int len=wildcard.length();
    
    for(int i=0;i<len;i++) {
        char c = wildcard.charAt(i);
        if(c == '*')sb.append(".*");
        else if(c == '?') sb.append('.');
        else if(specials.indexOf(c)!=-1)sb.append('\\').append(c);
        else sb.append(c);
    }
    
    this.ignoreCase=ignoreCase;
    pattern=new Perl5Compiler().compile(ignoreCase?StringUtil.toLowerCase(sb.toString()):sb.toString());
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:21,代碼來源:WildCardFilter.java

示例12: indexOf

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * return index of the first occurence of the pattern in input text
 * @param strPattern pattern to search
 * @param strInput text to search pattern
 * @param offset 
 * @param caseSensitive
 * @return position of the first occurence
 * @throws MalformedPatternException
*/
public static int indexOf(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
       //Perl5Compiler compiler = new Perl5Compiler();
       PatternMatcherInput input = new PatternMatcherInput(strInput);
       Perl5Matcher matcher = new Perl5Matcher();
       
       int compileOptions=caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
       compileOptions+=Perl5Compiler.SINGLELINE_MASK;
       if(offset < 1) offset = 1;
       
       Pattern pattern = getPattern(strPattern,compileOptions);
       //Pattern pattern = compiler.compile(strPattern,compileOptions);
       

       if(offset <= strInput.length()) input.setCurrentOffset(offset - 1);
       
       if(offset <= strInput.length() && matcher.contains(input, pattern)) {
           return matcher.getMatch().beginOffset(0) + 1; 
       }
       return 0;
   }
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:30,代碼來源:Perl5Util.java

示例13: WildCardFilter

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * @param wildcard
 * @throws MalformedPatternException
 */
public WildCardFilter(String wildcard,boolean ignoreCase) throws MalformedPatternException {
    this.wildcard=wildcard;
    this.ignoreCase=ignoreCase;
    StringBuilder sb = new StringBuilder(wildcard.length());
    int len=wildcard.length();
    
    for(int i=0;i<len;i++) {
        char c = wildcard.charAt(i);
        if(c == '*')sb.append(".*");
        else if(c == '?') sb.append('.');
        else if(specials.indexOf(c)!=-1)sb.append('\\').append(c);
        else sb.append(c);
    }
    pattern=new Perl5Compiler().compile(ignoreCase?sb.toString().toLowerCase():sb.toString());
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:20,代碼來源:WildCardFilter.java

示例14: isValidSettings

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
@Override
public List<ErrorData> isValidSettings(Map<Integer, Object> settings) {
	List<ErrorData> errorDataList = new ArrayList<ErrorData>();
	TTextBoxSettingsBean textBoxSettingsBean = (TTextBoxSettingsBean)settings.get(mapParameterCode);
	//textBoxSettingsBean can be null when no settings was set (especially by system fields)
	if (textBoxSettingsBean!=null) {
		String patternString = textBoxSettingsBean.getDefaultText();
		Perl5Compiler pc = new Perl5Compiler();
		try {
			/*Perl5Pattern pattern=(Perl5Pattern)*/pc.compile(patternString,Perl5Compiler.CASE_INSENSITIVE_MASK |Perl5Compiler.SINGLELINE_MASK);
		} catch (MalformedPatternException e) {
			LOGGER.error("Malformed Email Domain Pattern " + patternString);
			errorDataList.add(new ErrorData("admin.user.profile.err.emailAddress.format"));
		}
	}
	return errorDataList;
}
 
開發者ID:trackplus,項目名稱:Genji,代碼行數:18,代碼來源:EmaiAddressDT.java

示例15: validateRegEx

import org.apache.oro.text.regex.Perl5Compiler; //導入依賴的package包/類
/**
 * Helper method to validate the specified string does not contain anything other than
 * that specified by the regular expression
 * @param aErrors The errors object to populate
 * @param aValue the string to check
 * @param aRegEx the Perl based regular expression to check the value against
 * @param aErrorCode the error code for getting the i8n failure message
 * @param aValues the list of values to replace in the i8n messages
 * @param aFailureMessage the default error message
 */
public static void validateRegEx(Errors aErrors, String aValue, String aRegEx, String aErrorCode, Object[] aValues, String aFailureMessage) {
    if (aValue != null && aRegEx != null && !aRegEx.equals("") && !aValue.trim().equals("")) {
        Perl5Compiler ptrnCompiler = new Perl5Compiler();
        Perl5Matcher matcher = new Perl5Matcher();
        try {
            Perl5Pattern aCharPattern = (Perl5Pattern) ptrnCompiler.compile(aRegEx);
                            
            if (!matcher.contains(aValue, aCharPattern)) {
                aErrors.reject(aErrorCode, aValues, aFailureMessage);               
                return;
            }
        }
        catch (MalformedPatternException e) {
            LogFactory.getLog(ValidatorUtil.class).fatal("Perl pattern malformed: pattern used was "+aRegEx +" : "+ e.getMessage(), e);
        }           
    }
}
 
開發者ID:DIA-NZ,項目名稱:webcurator,代碼行數:28,代碼來源:ValidatorUtil.java


注:本文中的org.apache.oro.text.regex.Perl5Compiler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。