1 package org.apache.oro.text.regex; 2 3 59 60 69 final class Perl5MatchResult implements MatchResult { 70 78 int _matchBeginOffset; 79 80 81 96 int[] _beginGroupOffset, _endGroupOffset; 97 98 99 102 String _match; 103 104 105 114 Perl5MatchResult(int groups){ 115 _beginGroupOffset = new int[groups]; 116 _endGroupOffset = new int[groups]; 117 } 118 119 120 123 public int length(){ 124 return _match.length(); 125 } 126 127 128 134 public int groups(){ 135 return _beginGroupOffset.length; 136 } 137 138 146 public String group(int group){ 147 int begin, end, length; 148 149 if(group < _beginGroupOffset.length){ 150 begin = _beginGroupOffset[group]; 151 end = _endGroupOffset[group]; 152 length = _match.length(); 153 154 if(begin >= 0 && end >= 0) { 155 if(begin < length && end <= length && end > begin) 156 return _match.substring(begin, end); 157 else if(begin <= end) 158 return ""; 159 } 160 } 161 162 return null; 163 } 164 165 171 public int begin(int group){ 172 int begin, end; if(group < _beginGroupOffset.length){ 174 begin = _beginGroupOffset[group]; 175 end = _endGroupOffset[group]; 176 if(begin >= 0 && end >= 0) return begin; 180 } 181 182 return -1; 183 } 184 185 192 public int end(int group){ 193 int begin, end; if(group < _beginGroupOffset.length){ 195 begin = _beginGroupOffset[group]; 196 end = _endGroupOffset[group]; 197 if(begin >= 0 && end >= 0) return end; 201 } 202 return -1; 203 } 204 205 214 public int beginOffset(int group){ 215 int begin, end; if(group < _beginGroupOffset.length){ 217 begin = _beginGroupOffset[group]; 218 end = _endGroupOffset[group]; 219 if(begin >= 0 && end >= 0) return _matchBeginOffset + begin; 223 } 224 return -1; 225 } 226 227 237 public int endOffset(int group){ 238 int begin, end; if(group < _endGroupOffset.length){ 240 begin = _beginGroupOffset[group]; 241 end = _endGroupOffset[group]; 242 if(begin >= 0 && end >= 0) return _matchBeginOffset + end; 246 } 247 return -1; 248 } 249 250 251 256 public String toString() { 257 return group(0); 258 } 259 } 260 | Popular Tags |