PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 72 lines | 39 code | 13 blank | 20 comment | 5 complexity | 8dcdb05e1f2db05ef4cac7e21534a971 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/RETokenChar.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 RETokenChar extends REToken {
  21. private char[] ch;
  22. private boolean insens;
  23. RETokenChar(int subIndex, char c, boolean ins) {
  24. super(subIndex);
  25. ch = new char [1];
  26. ch[0] = (insens = ins) ? Character.toLowerCase(c) : c;
  27. }
  28. int getMinimumLength() {
  29. return ch.length;
  30. }
  31. boolean match(CharIndexed input, REMatch mymatch) {
  32. int z = ch.length;
  33. char c;
  34. for (int i=0; i<z; i++) {
  35. c = input.charAt(mymatch.index+i);
  36. if (( (insens) ? Character.toLowerCase(c) : c ) != ch[i]) {
  37. return false;
  38. }
  39. }
  40. mymatch.index += z;
  41. return next(input, mymatch);
  42. }
  43. // Overrides REToken.chain() to optimize for strings
  44. boolean chain(REToken next) {
  45. if (next instanceof RETokenChar) {
  46. RETokenChar cnext = (RETokenChar) next;
  47. // assume for now that next can only be one character
  48. int newsize = ch.length + cnext.ch.length;
  49. char[] chTemp = new char [newsize];
  50. System.arraycopy(ch,0,chTemp,0,ch.length);
  51. System.arraycopy(cnext.ch,0,chTemp,ch.length,cnext.ch.length);
  52. ch = chTemp;
  53. return false;
  54. } else return super.chain(next);
  55. }
  56. void dump(StringBuffer os) {
  57. os.append(ch);
  58. }
  59. }