|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 42-47
Link Here
|
| 42 |
protected Map fWords= new HashMap(); |
42 |
protected Map fWords= new HashMap(); |
| 43 |
/** Buffer used for pattern detection */ |
43 |
/** Buffer used for pattern detection */ |
| 44 |
private StringBuffer fBuffer= new StringBuffer(); |
44 |
private StringBuffer fBuffer= new StringBuffer(); |
|
|
45 |
/** The boolean repsenting whether we should be case sensitive */ |
| 46 |
private boolean fIgnoreCase = false; |
| 45 |
|
47 |
|
| 46 |
/** |
48 |
/** |
| 47 |
* Creates a rule which, with the help of an word detector, will return the token |
49 |
* Creates a rule which, with the help of an word detector, will return the token |
|
Lines 76-81
Link Here
|
| 76 |
fDetector= detector; |
78 |
fDetector= detector; |
| 77 |
fDefaultToken= defaultToken; |
79 |
fDefaultToken= defaultToken; |
| 78 |
} |
80 |
} |
|
|
81 |
|
| 82 |
/** |
| 83 |
* Creates a rule which, with the help of a word detector, will return the token |
| 84 |
* associated with the detected word. If no token has been associated, the |
| 85 |
* specified default token will be returned. |
| 86 |
* |
| 87 |
* @param detector the word detector to be used by this rule, may not be <code>null</code> |
| 88 |
* @param defaultToken the default token to be returned on success |
| 89 |
* if nothing else is specified, may not be <code>null</code> |
| 90 |
* @param ignoreCase the case sensitivity associated with the rule |
| 91 |
* |
| 92 |
* @see #addWord(String, IToken) |
| 93 |
*/ |
| 94 |
public WordRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase) { |
| 95 |
|
| 96 |
Assert.isNotNull(detector); |
| 97 |
Assert.isNotNull(defaultToken); |
| 98 |
|
| 99 |
fDetector= detector; |
| 100 |
fDefaultToken= defaultToken; |
| 101 |
setIgnoreCase(ignoreCase); |
| 102 |
} |
| 79 |
|
103 |
|
| 80 |
/** |
104 |
/** |
| 81 |
* Adds a word and the token to be returned if it is detected. |
105 |
* Adds a word and the token to be returned if it is detected. |
|
Lines 87-93
Link Here
|
| 87 |
Assert.isNotNull(word); |
111 |
Assert.isNotNull(word); |
| 88 |
Assert.isNotNull(token); |
112 |
Assert.isNotNull(token); |
| 89 |
|
113 |
|
| 90 |
fWords.put(word, token); |
114 |
if(!fIgnoreCase) |
|
|
115 |
fWords.put(word, token); |
| 116 |
else |
| 117 |
fWords.put(word.toUpperCase(), token); |
| 91 |
} |
118 |
} |
| 92 |
|
119 |
|
| 93 |
/** |
120 |
/** |
|
Lines 118-125
Link Here
|
| 118 |
c= scanner.read(); |
145 |
c= scanner.read(); |
| 119 |
} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)); |
146 |
} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)); |
| 120 |
scanner.unread(); |
147 |
scanner.unread(); |
|
|
148 |
|
| 149 |
String buffer= fIgnoreCase ? fBuffer.toString().toUpperCase() : fBuffer.toString(); |
| 121 |
|
150 |
|
| 122 |
IToken token= (IToken) fWords.get(fBuffer.toString()); |
151 |
IToken token= (IToken) fWords.get(buffer); |
| 123 |
if (token != null) |
152 |
if (token != null) |
| 124 |
return token; |
153 |
return token; |
| 125 |
|
154 |
|
|
Lines 143-146
Link Here
|
| 143 |
for (int i= fBuffer.length() - 1; i >= 0; i--) |
172 |
for (int i= fBuffer.length() - 1; i >= 0; i--) |
| 144 |
scanner.unread(); |
173 |
scanner.unread(); |
| 145 |
} |
174 |
} |
|
|
175 |
|
| 176 |
/** |
| 177 |
* Sets the case sensitivity for this rule |
| 178 |
* |
| 179 |
* @param value the case sensitivity value |
| 180 |
* @since 3.3 |
| 181 |
*/ |
| 182 |
public void setIgnoreCase(boolean value) { |
| 183 |
this.fIgnoreCase = value; |
| 184 |
} |
| 185 |
|
| 146 |
} |
186 |
} |