PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 68 lines | 38 code | 6 blank | 24 comment | 8 complexity | 71247d1b97362fab6a90113112fe9e14 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/RETokenOneOf.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. /**
  21. * @since gnu.regexp 1.1.3
  22. * @author Shashank Bapat
  23. */
  24. final class RETokenLookAhead extends REToken
  25. {
  26. REToken re;
  27. boolean negative;
  28. RETokenLookAhead(REToken re, boolean negative) throws REException {
  29. super(0);
  30. this.re = re;
  31. this.negative = negative;
  32. }
  33. boolean match(CharIndexed input, REMatch mymatch)
  34. {
  35. REMatch trymatch = (REMatch)mymatch.clone();
  36. REMatch trymatch1 = (REMatch)mymatch.clone();
  37. REMatch newMatch = null;
  38. if (re.match(input, trymatch)) {
  39. if (negative) return false;
  40. if (next(input, trymatch1))
  41. newMatch = trymatch1;
  42. }
  43. if (newMatch != null) {
  44. if (negative) return false;
  45. //else
  46. mymatch.assignFrom(newMatch);
  47. return true;
  48. }
  49. else { // no match
  50. if (negative)
  51. return next(input, mymatch);
  52. //else
  53. return false;
  54. }
  55. }
  56. void dump(StringBuffer os) {
  57. os.append("(?");
  58. os.append(negative ? '!' : '=');
  59. re.dumpAll(os);
  60. os.append(')');
  61. }
  62. }