Coverage Report - net.sf.json.regexp.JdkRegexpMatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
JdkRegexpMatcher
0%
0/12
0%
0/4
1.75
 
 1  
 /*
 2  
  * Copyright 2002-2009 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package net.sf.json.regexp;
 18  
 
 19  
 import java.util.regex.Matcher;
 20  
 import java.util.regex.Pattern;
 21  
 
 22  
 /**
 23  
  * JDK 1.4+ RegexpMatcher implementation.
 24  
  * 
 25  
  * @author Andres Almiray <aalmiray@users.sourceforge.net>
 26  
  */
 27  
 public class JdkRegexpMatcher implements RegexpMatcher {
 28  
    private final Pattern pattern;
 29  
 
 30  
    public JdkRegexpMatcher( String pattern ) {
 31  0
       this( pattern, false );
 32  0
    }
 33  
 
 34  0
    public JdkRegexpMatcher( String pattern, boolean multiline ) {
 35  0
       if( multiline ) {
 36  0
          this.pattern = Pattern.compile( pattern, Pattern.MULTILINE );
 37  
       } else {
 38  0
          this.pattern = Pattern.compile( pattern );
 39  
       }
 40  0
    }
 41  
 
 42  
    public String getGroupIfMatches( String str, int group ) {
 43  0
       Matcher matcher = pattern.matcher( str );
 44  0
       if( matcher.matches() ) {
 45  0
          return matcher.group( group );
 46  
       }
 47  0
       return "";
 48  
    }
 49  
 
 50  
    public boolean matches( String str ) {
 51  0
       return pattern.matcher( str ).matches();
 52  
    }
 53  
 }