1 package org.apache.oro.text.regex; 2 3 59 60 120 public final class PatternMatcherInput { 121 String _originalStringInput; 122 char[] _originalCharInput, _originalBuffer, _toLowerBuffer; 123 int _beginOffset, _endOffset, _currentOffset; 124 int _matchBeginOffset = -1, _matchEndOffset = -1; 125 126 140 public PatternMatcherInput(String input, int begin, int length) { 141 setInput(input, begin, length); 142 } 143 144 152 public PatternMatcherInput(String input) { 153 this(input, 0, input.length()); 154 } 155 156 157 172 public PatternMatcherInput(char[] input, int begin, int length) { 173 setInput(input, begin, length); 174 } 175 176 184 public PatternMatcherInput(char[] input) { 185 this(input, 0, input.length); 186 } 187 188 189 194 public int length() { 195 return (_endOffset - _beginOffset); 196 } 198 199 200 212 public void setInput(String input, int begin, int length) { 213 _originalStringInput = input; 214 _originalCharInput = null; 215 _toLowerBuffer = null; 216 _originalBuffer = input.toCharArray(); 217 setCurrentOffset(begin); 218 setBeginOffset(begin); 219 setEndOffset(_beginOffset + length); 220 } 221 222 230 public void setInput(String input) { 231 setInput(input, 0, input.length()); 232 } 233 234 235 249 public void setInput(char[] input, int begin, int length) { 250 _originalStringInput = null; 251 _toLowerBuffer = null; 252 _originalBuffer = _originalCharInput = input; 253 setCurrentOffset(begin); 254 setBeginOffset(begin); 255 setEndOffset(_beginOffset + length); 256 } 257 258 259 267 public void setInput(char[] input) { 268 setInput(input, 0, input.length); 269 } 270 271 272 282 public char charAt(int offset) { 283 return _originalBuffer[_beginOffset + offset]; 284 } 285 286 300 public String substring(int beginOffset, int endOffset) { 301 return new String (_originalBuffer, _beginOffset+beginOffset, 302 endOffset - beginOffset); 303 } 304 305 317 public String substring(int beginOffset) { 318 beginOffset+=_beginOffset; 319 return new String (_originalBuffer, beginOffset, _endOffset - beginOffset); 320 } 321 322 323 333 public Object getInput(){ 334 if(_originalStringInput == null) 335 return _originalCharInput; 336 return _originalStringInput; 337 } 338 339 347 public char[] getBuffer() { return _originalBuffer; } 348 349 355 public boolean endOfInput(){ return (_currentOffset >= _endOffset); } 356 357 358 363 public int getBeginOffset() { return _beginOffset; } 364 365 371 public int getEndOffset() { return _endOffset; } 372 373 378 public int getCurrentOffset() { return _currentOffset; } 379 380 388 public void setBeginOffset(int offset) { _beginOffset = offset; } 389 390 398 public void setEndOffset(int offset) { _endOffset = offset; } 399 400 410 public void setCurrentOffset(int offset) { 411 _currentOffset = offset; 412 setMatchOffsets(-1, -1); 413 } 414 415 421 public String toString() { 422 return new String (_originalBuffer, _beginOffset, length()); 423 } 424 425 426 433 public String preMatch() { 434 return new String (_originalBuffer, _beginOffset, 435 _matchBeginOffset - _beginOffset); 436 } 437 438 439 446 public String postMatch() { 447 return new String (_originalBuffer, _matchEndOffset, 448 _endOffset - _matchEndOffset); 449 } 450 451 452 462 public String match() { 463 return new String (_originalBuffer, _matchBeginOffset, 464 _matchEndOffset - _matchBeginOffset); 465 } 466 467 468 484 public void setMatchOffsets(int matchBeginOffset, int matchEndOffset) { 485 _matchBeginOffset = matchBeginOffset; 486 _matchEndOffset = matchEndOffset; 487 } 488 489 495 public int getMatchBeginOffset() { return _matchBeginOffset; } 496 497 502 public int getMatchEndOffset() { return _matchEndOffset; } 503 } 504 | Popular Tags |