01: /*
02: * CharIndexedSegment.java
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 1998 Wes Biggs
07: * Copyright (C) 2000, 2001 Slava Pestov
08: *
09: * 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.util;
24:
25: //{{{ Imports
26: import java.io.Serializable;
27: import javax.swing.text.Segment;
28: import gnu.regexp.*;
29:
30: //}}}
31:
32: /**
33: * Lets <code>gnu.regexp</code> search within <code>Segment</code> objects.
34: *
35: * @deprecated Use {@link SegmentCharSequence} and the java.util.regex
36: * package instead.
37: */
38: public class CharIndexedSegment implements CharIndexed, Serializable {
39: //{{{ CharIndexedSegment constructor
40: /**
41: * Creates a new <code>CharIndexedSegment</code>.
42: * @since jEdit 4.1pre3
43: */
44: public CharIndexedSegment(Segment seg, int index) {
45: this .seg = seg;
46: m_index = index;
47: } //}}}
48:
49: //{{{ CharIndexedSegment constructor
50: /**
51: * Creates a new <code>CharIndexedSegment</code>.
52: * @since jEdit 4.1pre1
53: */
54: public CharIndexedSegment(Segment seg, boolean reverse) {
55: this .seg = seg;
56: m_index = (reverse ? seg.count - 1 : 0);
57: this .reverse = reverse;
58: } //}}}
59:
60: //{{{ charAt() method
61: public char charAt(int index) {
62: if (reverse)
63: index = -index;
64:
65: return ((m_index + index) < seg.count && m_index + index >= 0) ? seg.array[seg.offset
66: + m_index + index]
67: : CharIndexed.OUT_OF_BOUNDS;
68: } //}}}
69:
70: //{{{ isValid() method
71: public boolean isValid() {
72: return (m_index >= 0 && m_index < seg.count);
73: } //}}}
74:
75: //{{{ reset() method
76: public void reset() {
77: m_index = (reverse ? seg.count - 1 : 0);
78: } //}}}
79:
80: //{{{ move() method
81: public boolean move(int index) {
82: if (reverse)
83: index = -index;
84:
85: return ((m_index += index) < seg.count);
86: } //}}}
87:
88: //{{{ Private members
89: private Segment seg;
90: private int m_index;
91: private boolean reverse;
92: //}}}
93: }
|