Mercurial > projects > dwt-addons
comparison dwtx/jface/text/rules/WordPatternRule.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 51e6e63f930e |
children | eb98a5cbfd78 |
comparison
equal
deleted
inserted
replaced
161:f8d52b926852 | 162:1a5b8f8129df |
---|---|
54 public class WordPatternRule : SingleLineRule { | 54 public class WordPatternRule : SingleLineRule { |
55 | 55 |
56 /** The word detector used by this rule */ | 56 /** The word detector used by this rule */ |
57 protected IWordDetector fDetector; | 57 protected IWordDetector fDetector; |
58 /** The internal buffer used for pattern detection */ | 58 /** The internal buffer used for pattern detection */ |
59 private StringBuffer fBuffer= new StringBuffer(); | 59 private StringBuffer fBuffer; |
60 | 60 |
61 /** | 61 /** |
62 * Creates a rule for the given starting and ending word | 62 * Creates a rule for the given starting and ending word |
63 * pattern which, if detected, will return the specified token. | 63 * pattern which, if detected, will return the specified token. |
64 * A word detector is used to identify words. | 64 * A word detector is used to identify words. |
84 * @param endSequence the end sequence of the word pattern | 84 * @param endSequence the end sequence of the word pattern |
85 * @param token the token to be returned on success | 85 * @param token the token to be returned on success |
86 * @param escapeCharacter the escape character | 86 * @param escapeCharacter the escape character |
87 */ | 87 */ |
88 public this(IWordDetector detector, String startSequence, String endSequence, IToken token, char escapeCharacter) { | 88 public this(IWordDetector detector, String startSequence, String endSequence, IToken token, char escapeCharacter) { |
89 fBuffer= new StringBuffer(); | |
89 super(startSequence, endSequence, token, escapeCharacter); | 90 super(startSequence, endSequence, token, escapeCharacter); |
90 Assert.isNotNull(detector); | 91 Assert.isNotNull(cast(Object)detector); |
91 fDetector= detector; | 92 fDetector= detector; |
92 } | 93 } |
93 | 94 |
94 /** | 95 /** |
95 * Returns whether the end sequence was detected. | 96 * Returns whether the end sequence was detected. |
99 * | 100 * |
100 * @param scanner the scanner to be used | 101 * @param scanner the scanner to be used |
101 * @return <code>true</code> if the word ends on the given end sequence | 102 * @return <code>true</code> if the word ends on the given end sequence |
102 */ | 103 */ |
103 protected bool endSequenceDetected(ICharacterScanner scanner) { | 104 protected bool endSequenceDetected(ICharacterScanner scanner) { |
104 fBuffer.setLength(0); | 105 fBuffer.truncate(0); |
105 int c= scanner.read(); | 106 int c= scanner.read(); |
106 while (fDetector.isWordPart(cast(wchar) c)) { | 107 while (fDetector.isWordPart(cast(char) c)) { |
107 fBuffer.append(cast(wchar) c); | 108 fBuffer.append(cast(char) c); |
108 c= scanner.read(); | 109 c= scanner.read(); |
109 } | 110 } |
110 scanner.unread(); | 111 scanner.unread(); |
111 | 112 |
112 if (fBuffer.length() >= fEndSequence.length) { | 113 if (fBuffer.length() >= fEndSequence.length) { |
113 for (int i=fEndSequence.length - 1, j= fBuffer.length() - 1; i >= 0; i--, j--) { | 114 for (int i=fEndSequence.length - 1, j= fBuffer.length() - 1; i >= 0; i--, j--) { |
114 if (fEndSequence[i] !is fBuffer.charAt(j)) { | 115 if (fEndSequence[i] !is fBuffer.slice()[j]) { |
115 unreadBuffer(scanner); | 116 unreadBuffer(scanner); |
116 return false; | 117 return false; |
117 } | 118 } |
118 } | 119 } |
119 return true; | 120 return true; |
129 * read in as part of the start sequence expect the first one. | 130 * read in as part of the start sequence expect the first one. |
130 * | 131 * |
131 * @param scanner the scanner to be used | 132 * @param scanner the scanner to be used |
132 */ | 133 */ |
133 protected void unreadBuffer(ICharacterScanner scanner) { | 134 protected void unreadBuffer(ICharacterScanner scanner) { |
134 fBuffer.insert(0, fStartSequence); | 135 fBuffer.select(0, 0 ); |
136 fBuffer.replace(fStartSequence); | |
135 for (int i= fBuffer.length() - 1; i > 0; i--) | 137 for (int i= fBuffer.length() - 1; i > 0; i--) |
136 scanner.unread(); | 138 scanner.unread(); |
137 } | 139 } |
138 } | 140 } |