PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/gnu/regexp/RETokenStart.java

#
Java | 69 lines | 39 code | 9 blank | 21 comment | 13 complexity | ee80d04c88ac16f03bbb6550d160df72 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/RETokenStart.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. class RETokenStart extends REToken {
  21. private String newline; // matches after a newline
  22. RETokenStart(int subIndex, String newline) {
  23. super(subIndex);
  24. this.newline = newline;
  25. }
  26. boolean match(CharIndexed input, REMatch mymatch) {
  27. // charAt(index-n) may be unknown on a Reader/InputStream. FIXME
  28. // Match after a newline if in multiline mode
  29. if (newline != null) {
  30. int len = newline.length();
  31. if (mymatch.offset >= len) {
  32. boolean found = true;
  33. char z;
  34. int i = 0; // position in REToken.newline
  35. char ch = input.charAt(mymatch.index - len);
  36. do {
  37. z = newline.charAt(i);
  38. if (ch != z) {
  39. found = false;
  40. break;
  41. }
  42. ++i;
  43. ch = input.charAt(mymatch.index - len + i);
  44. } while (i < len);
  45. if (found) return next(input, mymatch);
  46. }
  47. }
  48. // Don't match at all if REG_NOTBOL is set.
  49. if ((mymatch.eflags & RE.REG_NOTBOL) > 0) return false;
  50. if ((mymatch.eflags & RE.REG_ANCHORINDEX) > 0)
  51. return (mymatch.anchor == mymatch.offset) ?
  52. next(input, mymatch) : false;
  53. else
  54. return ((mymatch.index == 0) && (mymatch.offset == 0)) ?
  55. next(input, mymatch) : false;
  56. }
  57. void dump(StringBuffer os) {
  58. os.append('^');
  59. }
  60. }