1 11 package org.eclipse.jface.text.rules; 12 13 14 import org.eclipse.core.runtime.Assert; 15 16 17 18 24 public class WordPatternRule extends SingleLineRule { 25 26 27 protected IWordDetector fDetector; 28 29 private StringBuffer fBuffer= new StringBuffer (); 30 31 41 public WordPatternRule(IWordDetector detector, String startSequence, String endSequence, IToken token) { 42 this(detector, startSequence, endSequence, token, (char)0); 43 } 44 45 58 public WordPatternRule(IWordDetector detector, String startSequence, String endSequence, IToken token, char escapeCharacter) { 59 super(startSequence, endSequence, token, escapeCharacter); 60 Assert.isNotNull(detector); 61 fDetector= detector; 62 } 63 64 73 protected boolean endSequenceDetected(ICharacterScanner scanner) { 74 fBuffer.setLength(0); 75 int c= scanner.read(); 76 while (fDetector.isWordPart((char) c)) { 77 fBuffer.append((char) c); 78 c= scanner.read(); 79 } 80 scanner.unread(); 81 82 if (fBuffer.length() >= fEndSequence.length) { 83 for (int i=fEndSequence.length - 1, j= fBuffer.length() - 1; i >= 0; i--, j--) { 84 if (fEndSequence[i] != fBuffer.charAt(j)) { 85 unreadBuffer(scanner); 86 return false; 87 } 88 } 89 return true; 90 } 91 92 unreadBuffer(scanner); 93 return false; 94 } 95 96 103 protected void unreadBuffer(ICharacterScanner scanner) { 104 fBuffer.insert(0, fStartSequence); 105 for (int i= fBuffer.length() - 1; i > 0; i--) 106 scanner.unread(); 107 } 108 } 109 | Popular Tags |