📄 aclsltokenmarker.java
字号:
return token;
}
/**
* Creates a new <code>TokenMarker</code>. This DOES NOT create a lineInfo
* array; an initial call to <code>insertLines()</code> does that.
*
* @param index Description of Parameter
*/
/**
* Creates a new <code>TokenMarker</code>. This DOES NOT create a lineInfo
* array; an initial call to <code>insertLines()</code> does that.
*
* Creates a new <code>TokenMarker</code>. This DOES NOT create a lineInfo
* array; an initial call to <code>insertLines()</code> does that. Creates
* a new <code>TokenMarker</code>. This DOES NOT create a lineInfo array;
* an initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Creates a new
* <code>TokenMarker</code>. This DOES NOT create a lineInfo array; an
* initial call to <code>insertLines()</code> does that. Ensures that the
* <code>lineInfo</code> array can contain the specified index. This
* enlarges it if necessary. No action is taken if the array is large
* enough already.<p>
*
* It should be unnecessary to call this under normal circumstances; <code>insertLine()</code>
* should take care of enlarging the line info array automatically.
*
* @param index Description of Parameter
*/
protected void ensureCapacity(int index) {
if (lineInfo == null) {
lineInfo = new LineInfo[index + 1];
}
else if (lineInfo.length <= index) {
LineInfo[] lineInfoN = new LineInfo[(index + 1) * 2];
System.arraycopy(lineInfo, 0, lineInfoN, 0,
lineInfo.length);
lineInfo = lineInfoN;
}
}
/**
* Adds a token to the token list.
*
* @param length The length of the token
* @param id The id of the token
*/
protected void addToken(int length, byte id) {
if (id >= ACLToken.INTERNAL_FIRST && id <= ACLToken.INTERNAL_LAST) {
throw new InternalError("Invalid id: " + id);
}
if (length == 0 && id != ACLToken.END) {
return;
}
if (firstToken == null) {
firstToken = new ACLToken(length, id);
lastToken = firstToken;
}
else if (lastToken == null) {
lastToken = firstToken;
firstToken.length = length;
firstToken.id = id;
}
else if (lastToken.next == null) {
lastToken.next = new ACLToken(length, id);
lastToken = lastToken.next;
}
else {
lastToken = lastToken.next;
lastToken.length = length;
lastToken.id = id;
}
}
private boolean doKeyword(Segment line, int i, char c) {
int i1 = i + 1;
if (token == S_END) {
addToken(i - lastOffset, ACLToken.LITERAL2);
token = ACLToken.NULL;
lastOffset = i;
lastKeyword = i1;
return false;
}
int len = i - lastKeyword;
byte id = keywords.lookup(line, lastKeyword, len);
if (id == S_ONE || id == S_TWO) {
if (lastKeyword != lastOffset) {
addToken(lastKeyword - lastOffset, ACLToken.NULL);
}
addToken(len, ACLToken.LITERAL2);
lastOffset = i;
lastKeyword = i1;
if (Character.isWhitespace(c)) {
matchChar = '\0';
}
else {
matchChar = c;
}
matchSpacesAllowed = true;
token = id;
return true;
}
else if (id != ACLToken.NULL) {
if (lastKeyword != lastOffset) {
addToken(lastKeyword - lastOffset, ACLToken.NULL);
}
addToken(len, id);
lastOffset = i;
}
lastKeyword = i1;
return false;
}
// ***EOF***
private static class KeywordMap {
/**
* Creates a new <code>KeywordMap</code>.
*
* @param ignoreCase True if keys are case insensitive
*/
public KeywordMap(boolean ignoreCase) {
this(ignoreCase, 52);
this.ignoreCase = ignoreCase;
}
/**
* Creates a new <code>KeywordMap</code>.
*
* @param ignoreCase True if the keys are case insensitive
* @param mapLength The number of `buckets' to create. A value of 52
* will give good performance for most maps.
*/
public KeywordMap(boolean ignoreCase, int mapLength) {
this.mapLength = mapLength;
this.ignoreCase = ignoreCase;
map = new Keyword[mapLength];
}
/**
* Returns true if the keyword map is set to be case insensitive, false
* otherwise.
*
* @return The IgnoreCase value
*/
public boolean getIgnoreCase() {
return ignoreCase;
}
/**
* Sets if the keyword map should be case insensitive.
*
* @param ignoreCase True if the keyword map should be case insensitive,
* false otherwise
*/
public void setIgnoreCase(boolean ignoreCase) {
this.ignoreCase = ignoreCase;
}
/**
* Looks up a key.
*
* @param text The text segment
* @param offset The offset of the substring within the text segment
* @param length The length of the substring
* @return Description of the Returned Value
*/
public byte lookup(Segment text, int offset, int length) {
if (length == 0) {
return ACLToken.NULL;
}
Keyword k = map[getSegmentMapKey(text, offset, length)];
while (k != null) {
if (length != k.keyword.length) {
k = k.next;
continue;
}
if (ACLSyntaxUtilities.regionMatches(ignoreCase, text, offset,
k.keyword)) {
return k.id;
}
k = k.next;
}
return ACLToken.NULL;
}
/**
* Adds a key-value mapping.
*
* @param keyword The key
* @param id Description of Parameter
* @Param id The value
*/
public void add(String keyword, byte id) {
int key = getStringMapKey(keyword);
map[key] = new Keyword(keyword.toCharArray(), id, map[key]);
}
protected int getStringMapKey(String s) {
return (Character.toUpperCase(s.charAt(0)) +
Character.toUpperCase(s.charAt(s.length() - 1)))
% mapLength;
}
protected int getSegmentMapKey(Segment s, int off, int len) {
return (Character.toUpperCase(s.array[off]) +
Character.toUpperCase(s.array[off + len - 1]))
% mapLength;
}
// private members
class Keyword {
public Keyword(char[] keyword, byte id, Keyword next) {
this.keyword = keyword;
this.id = id;
this.next = next;
}
public char[] keyword;
public byte id;
public Keyword next;
}
// protected members
protected int mapLength;
private Keyword[] map;
private boolean ignoreCase;
}
/**
* Inner class for storing information about tokenized lines.
*
* @author chris
* @created June 8, 2002
*/
public class LineInfo {
/**
* Creates a new LineInfo object with token = Token.NULL and obj = null.
*/
public LineInfo() { }
/**
* Creates a new LineInfo object with the specified parameters.
*
* @param token Description of Parameter
* @param obj Description of Parameter
*/
public LineInfo(byte token, Object obj) {
this.token = token;
this.obj = obj;
}
/**
* The id of the last token of the line.
*/
public byte token;
/**
* This is for use by the token marker implementations themselves. It can
* be used to store anything that is an object and that needs to exist on
* a per-line basis.
*/
public Object obj;
}
// public members
public final static byte S_ONE = ACLToken.INTERNAL_FIRST;
public final static byte S_TWO = (byte)(ACLToken.INTERNAL_FIRST + 1);
public final static byte S_END = (byte)(ACLToken.INTERNAL_FIRST + 2);
private static KeywordMap aclSLKeywords;
// protected members
/**
* The first token in the list. This should be used as the return value
* from <code>markTokens()</code>.
*/
protected ACLToken firstToken;
/**
* The last token in the list. New tokens are added here. This should be
* set to null before a new line is to be tokenized.
*/
protected ACLToken lastToken;
/**
* An array for storing information about lines. It is enlarged and shrunk
* automatically by the <code>insertLines()</code> and <code>deleteLines()</code>
* methods.
*/
protected LineInfo[] lineInfo;
/**
* The length of the <code>lineInfo</code> array.
*/
protected int length;
/**
* The last tokenized line.
*/
protected int lastLine;
/**
* True if the next line should be painted.
*/
protected boolean nextLineRequested;
// private members
private KeywordMap keywords;
private byte token;
private int lastOffset;
private int lastKeyword;
private char matchChar;
private boolean matchCharBracket;
private boolean matchSpacesAllowed;
}
// ***EOF***
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -