1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
String mot;
String[] tests = {"if", "then", "else"};
// tests c'est pour l'exemple
String masq = "(^|\\s*|\\p{Punct})+";
String masq2 = "(\\s+.*|\\p{Punct}|$)+";
Matcher matcher;
int i, j, f, d;
for (int k = 0; k < tests.length; k++) {
mot = tests[k];
i = j = 0;
while ((j = text.indexOf(masq+mot+masq2, i)) != -1) {
i = j;
matcher = Pattern.compile( mot , Pattern.MULTILINE).matcher(text.substring(i));
if (matcher.find()) {
j = matcher.end() + i - 1;
doc.setCharacterAttributes(i + start, mot.length(), forbiddenkeyWordsStyle, true);
i += mot.length();
i = j;
}
}
} |
Partager