001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.util;
016    
017    /**
018     * A "friendly" version of a regular expression match. 
019     */
020    public class RegexpMatch
021    {
022        private final int _groupCount;
023        private final String[] _groups;
024    
025        RegexpMatch(int groupCount, String[] groups)
026        {
027            _groupCount = groupCount;
028            _groups = groups;
029        }
030    
031        /**
032         * Returns a matching group within the input string. Group 0 is the entire input string, group 1
033         * is the content with the first expression, etc.
034         */
035    
036        public String getGroup(int group)
037        {
038            return _groups[group];
039        }
040    
041        /**
042         * Returns the entire matching input.
043         */
044    
045        public String getInput()
046        {
047            return _groups[0];
048        }
049        
050        public int getMatchLength()
051        {
052            return _groups[0].length();
053        }
054    }