1 23 package org.gjt.sp.util; 24 25 import java.io.Serializable ; 27 import javax.swing.text.Segment ; 28 import gnu.regexp.*; 29 31 37 public class CharIndexedSegment implements CharIndexed, Serializable 38 { 39 44 public CharIndexedSegment(Segment seg, int index) 45 { 46 this.seg = seg; 47 m_index = index; 48 } 50 55 public CharIndexedSegment(Segment seg, boolean reverse) 56 { 57 this.seg = seg; 58 m_index = (reverse ? seg.count - 1 : 0); 59 this.reverse = reverse; 60 } 62 public char charAt(int index) 64 { 65 if(reverse) 66 index = -index; 67 68 return ((m_index + index) < seg.count && m_index + index >= 0) 69 ? seg.array[seg.offset + m_index + index] 70 : CharIndexed.OUT_OF_BOUNDS; 71 } 73 public boolean isValid() 75 { 76 return (m_index >=0 && m_index < seg.count); 77 } 79 public void reset() 81 { 82 m_index = (reverse ? seg.count - 1 : 0); 83 } 85 public boolean move(int index) 87 { 88 if(reverse) 89 index = -index; 90 91 return ((m_index += index) < seg.count); 92 } 94 private Segment seg; 96 private int m_index; 97 private boolean reverse; 98 } 100 | Popular Tags |