PageRenderTime 56ms CodeModel.GetById 49ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 72 lines | 34 code | 8 blank | 30 comment | 4 complexity | 92455a57e9bdcd4c184ba21f05d739f5 MD5 | raw file
 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 */
23package org.gjt.sp.jedit.search;
24
25//{{{ Imports
26import java.io.Serializable;
27import javax.swing.text.Segment;
28import gnu.regexp.*;
29 //}}}
30
31public class CharIndexedSegment implements CharIndexed, Serializable
32{
33	//{{{ CharIndexedSegment constructor
34	CharIndexedSegment(Segment seg, boolean reverse)
35	{
36		this.seg = seg;
37		m_index = (reverse ? seg.count - 1 : 0);
38		this.reverse = reverse;
39	} //}}}
40
41	//{{{ charAt() method
42	public char charAt(int index)
43	{
44		if(reverse)
45			index = -index;
46
47		return ((m_index + index) < seg.count && m_index + index >= 0)
48			? seg.array[seg.offset + m_index + index]
49			: CharIndexed.OUT_OF_BOUNDS;
50	} //}}}
51
52	//{{{ isValid() method
53	public boolean isValid()
54	{
55		return (m_index >=0 && m_index < seg.count);
56	} //}}}
57
58	//{{{ move() method
59	public boolean move(int index)
60	{
61		if(reverse)
62			index = -index;
63
64		return ((m_index += index) < seg.count);
65	} //}}}
66
67	//{{{ Private members
68	private Segment seg;
69	private int m_index;
70	private boolean reverse;
71	//}}}
72}