1 11 12 package org.eclipse.jdt.internal.ui.text.spelling; 13 14 import com.ibm.icu.text.BreakIterator; 15 import java.text.CharacterIterator ; 16 import java.util.Locale ; 17 18 23 public class PropertiesValueBreakIterator extends BreakIterator { 24 25 26 private BreakIterator fParent; 27 28 29 private CharacterIterator fText; 30 31 36 public PropertiesValueBreakIterator(Locale locale) { 37 fParent= BreakIterator.getWordInstance(locale); 38 } 39 40 43 public int current() { 44 return correct(fParent.current()); 45 } 46 47 50 public int first() { 51 return fParent.first(); 52 } 53 54 57 public int last() { 58 return fParent.last(); 59 } 60 61 64 public int next() { 65 int next= fParent.next(); 66 while (!stopAt(next)) 67 next= fParent.next(); 68 return correct(next); 69 } 70 71 74 public int previous() { 75 int previous= fParent.previous(); 76 while (!stopAt(previous)) 77 previous= fParent.previous(); 78 return correct(previous); 79 } 80 81 84 public int following(int offset) { 85 int following= fParent.following(offset); 86 while (!stopAt(following)) 87 following= fParent.following(offset); 88 return correct(following); 89 } 90 91 94 public int next(int n) { 95 int next= fParent.next(n); 96 while (!stopAt(next)) 97 next= fParent.next(n); 98 return correct(next); 99 } 100 101 104 public CharacterIterator getText() { 105 return fParent.getText(); 106 } 107 108 111 public void setText(CharacterIterator newText) { 112 fText= newText; 113 fParent.setText(newText); 114 } 115 116 122 private boolean stopAt(int index) { 123 if (index == BreakIterator.DONE) 124 return true; 125 if (index > getBeginIndex() && index < getEndIndex() - 1 && !Character.isWhitespace(charAt(index - 1)) && !Character.isWhitespace(charAt(index)) && (charAt(index - 1) == '&' || charAt(index) == '&')) 126 return false; 127 return true; 128 } 129 130 136 private int correct(int index) { 137 if (index == BreakIterator.DONE) 138 return index; 139 if (index > getBeginIndex() && index < getEndIndex() - 1 && !Character.isWhitespace(charAt(index - 1)) && charAt(index - 1) == '\\') 140 return index - 1; 141 return index; 142 } 143 144 150 private char charAt(int index) { 151 int oldIndex= fText.getIndex(); 152 char ch= fText.setIndex(index); 153 fText.setIndex(oldIndex); 154 return ch; 155 } 156 157 162 private int getEndIndex() { 163 return fText.getEndIndex(); 164 } 165 166 171 private int getBeginIndex() { 172 return fText.getBeginIndex(); 173 } 174 } 175 | Popular Tags |