1 30 31 package org.syntax.jedit; 32 33 import java.util.*; 34 35 import org.syntax.jedit.tokenmarker.*; 36 import javax.swing.text.Segment ; 37 38 public class IReportKeywordLookup implements KeywordLookupIF 39 { 40 private ArrayList keys = new ArrayList(); 41 42 public IReportKeywordLookup() 43 { 44 } 45 46 public void addKeyword(String keyword) 47 { 48 addKeyword(keyword, Token.PARAMETER_OK); 49 } 50 51 public void addKeyword(String keyword, byte token) 52 { 53 keys.add(new Key(keyword, token)); 55 } 56 57 public void removeKeyword(String keyword) 58 { 59 Key key; 60 61 for(int i=0; i<keys.size(); i++) 62 { 63 key = (Key) keys.get(i); 64 if(key.keyword.equals(keyword)) 65 { 66 keys.remove(key); 67 } 68 } 69 } 70 71 77 public byte lookup(Segment text, int offset, int length) 78 { 79 Key key; 80 String keyword; 81 boolean found; 82 83 for(int i=0; i<keys.size(); i++) 84 { 85 key = (Key) keys.get(i); 86 keyword = key.keyword; 87 88 if(keyword.length() != length) 89 { 90 continue; 91 } 92 93 found = true; 94 for(int j=0; j<keyword.length(); j++) 95 { 96 if(keyword.charAt(j) != text.array[offset + j]) 97 { 98 found = false; 99 break; 100 } 101 } 102 103 if(found) 104 { 105 return key.token; 106 } 107 } 108 109 return Token.NULL; 110 } 111 112 private class Key 113 { 114 String keyword; 115 byte token; 116 117 Key(String keyword, byte token) 118 { 119 this.keyword = keyword; 120 this.token = token; 121 } 122 } 123 124 } 125 | Popular Tags |