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

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/search/CharIndexedSegment.java

#
Java | 72 lines | 34 code | 8 blank | 30 comment | 4 complexity | 92455a57e9bdcd4c184ba21f05d739f5 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. * CharIndexedSegment.java
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1998 Wes Biggs
  7. * Copyright (C) 2000, 2001 Slava Pestov
  8. *
  9. * This library is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Library General Public License as published
  11. * by the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Library General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Library General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. package org.gjt.sp.jedit.search;
  24. //{{{ Imports
  25. import java.io.Serializable;
  26. import javax.swing.text.Segment;
  27. import gnu.regexp.*;
  28. //}}}
  29. public class CharIndexedSegment implements CharIndexed, Serializable
  30. {
  31. //{{{ CharIndexedSegment constructor
  32. CharIndexedSegment(Segment seg, boolean reverse)
  33. {
  34. this.seg = seg;
  35. m_index = (reverse ? seg.count - 1 : 0);
  36. this.reverse = reverse;
  37. } //}}}
  38. //{{{ charAt() method
  39. public char charAt(int index)
  40. {
  41. if(reverse)
  42. index = -index;
  43. return ((m_index + index) < seg.count && m_index + index >= 0)
  44. ? seg.array[seg.offset + m_index + index]
  45. : CharIndexed.OUT_OF_BOUNDS;
  46. } //}}}
  47. //{{{ isValid() method
  48. public boolean isValid()
  49. {
  50. return (m_index >=0 && m_index < seg.count);
  51. } //}}}
  52. //{{{ move() method
  53. public boolean move(int index)
  54. {
  55. if(reverse)
  56. index = -index;
  57. return ((m_index += index) < seg.count);
  58. } //}}}
  59. //{{{ Private members
  60. private Segment seg;
  61. private int m_index;
  62. private boolean reverse;
  63. //}}}
  64. }