PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-0-pre5/gnu/regexp/RETokenBackRef.java

#
Java | 53 lines | 26 code | 8 blank | 19 comment | 4 complexity | 55166ce7fb8a52ade317b6a96e19242a MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * gnu/regexp/RETokenBackRef.java
  3. * Copyright (C) 1998-2001 Wes Biggs
  4. *
  5. * This library is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published
  7. * by the Free Software Foundation; either version 2.1 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. package gnu.regexp;
  20. final class RETokenBackRef extends REToken {
  21. private int num;
  22. private boolean insens;
  23. RETokenBackRef(int subIndex, int num, boolean insens) {
  24. super(subIndex);
  25. this.num = num;
  26. this.insens = insens;
  27. }
  28. // should implement getMinimumLength() -- any ideas?
  29. boolean match(CharIndexed input, REMatch mymatch) {
  30. int b,e;
  31. b = mymatch.start[num];
  32. e = mymatch.end[num];
  33. if ((b==-1)||(e==-1)) return false; // this shouldn't happen, but...
  34. for (int i=b; i<e; i++) {
  35. if (input.charAt(mymatch.index+i-b) != input.charAt(i)) {
  36. return false;
  37. }
  38. }
  39. mymatch.index += e-b;
  40. return next(input, mymatch);
  41. }
  42. void dump(StringBuffer os) {
  43. os.append('\\').append(num);
  44. }
  45. }