Package org.fife.ui.rsyntaxtextarea
Class TokenUtils
java.lang.Object
org.fife.ui.rsyntaxtextarea.TokenUtils
Utility methods for dealing with tokens.
- Version:
- 1.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TokenUtils.TokenSubList
getSubTokenList
(Token tokenList, int pos, TabExpander e, RSyntaxTextArea textArea, float x0) Modifies the passed-in token list to start at the specified offset.static TokenUtils.TokenSubList
getSubTokenList
(Token tokenList, int pos, TabExpander e, RSyntaxTextArea textArea, float x0, TokenImpl tempToken) Modifies the passed-in token list to start at the specified offset.static int
getWhiteSpaceTokenLength
(Token t, int tabSize, int curOffs) Returns the length, in characters, of a whitespace token, taking tabs into account.static boolean
Returns whether a token list isnull
, empty, all whitespace, just comment token(s), or any combination of those.static boolean
Returns whether a token list isnull
, empty, or all whitespace token(s).static String
tokenToHtml
(RSyntaxTextArea textArea, Token token) Generates HTML that renders a token with the style used in an RSTA instance.
-
Constructor Details
-
TokenUtils
private TokenUtils()
-
-
Method Details
-
getSubTokenList
public static TokenUtils.TokenSubList getSubTokenList(Token tokenList, int pos, TabExpander e, RSyntaxTextArea textArea, float x0) Modifies the passed-in token list to start at the specified offset. For example, if the token list covered positions 20-60 in the document (inclusive) like so:[token1] -> [token2] -> [token3] -> [token4] 20 30 31 40 41 50 51 60
and you used this method to make the token list start at position 44, then the token list would be modified to be the following:[part-of-old-token3] -> [token4] 44 50 51 60
Tokens that come before the specified position are forever lost, and the token containing that position is made to begin at that position if necessary. All token types remain the same as they were originally.This method can be useful if you are only interested in part of a token list (i.e., the line it represents), but you don't want to modify the token list yourself.
- Parameters:
tokenList
- The list to make start at the specified position. This parameter is modified.pos
- The position at which the new token list is to start. If this position is not in the passed-in token list, the returned token list will either benull
or the unpaintable token(s) at the end of the passed-in token list.e
- How to expand tabs.textArea
- The text area from which the token list came.x0
- The initial x-pixel position of the old token list.- Returns:
- Information about the "sub" token list. This will be
null
ifpos
was not a valid offset into the token list. - See Also:
-
getSubTokenList
public static TokenUtils.TokenSubList getSubTokenList(Token tokenList, int pos, TabExpander e, RSyntaxTextArea textArea, float x0, TokenImpl tempToken) Modifies the passed-in token list to start at the specified offset. For example, if the token list covered positions 20-60 in the document (inclusive) like so:[token1] -> [token2] -> [token3] -> [token4] 20 30 31 40 41 50 51 60
and you used this method to make the token list start at position 44, then the token list would be modified to be the following:[part-of-old-token3] -> [token4] 44 50 51 60
Tokens that come before the specified position are forever lost, and the token containing that position is made to begin at that position if necessary. All token types remain the same as they were originally.This method can be useful if you are only interested in part of a token list (i.e., the line it represents), but you don't want to modify the token list yourself.
- Parameters:
tokenList
- The list to make start at the specified position. This parameter is modified.pos
- The position at which the new token list is to start. If this position is not in the passed-in token list, the returned token list will either benull
or the unpaintable token(s) at the end of the passed-in token list.e
- How to expand tabs.textArea
- The text area from which the token list came.x0
- The initial x-pixel position of the old token list.tempToken
- A temporary token to use when creating the token list result. This may benull
but callers can pass in a "buffer" token for performance if desired.- Returns:
- Information about the "sub" token list. This will be
null
ifpos
was not a valid offset into the token list. - See Also:
-
getWhiteSpaceTokenLength
Returns the length, in characters, of a whitespace token, taking tabs into account.- Parameters:
t
- The token. This should be of typeTokenTypes.WHITESPACE
.tabSize
- The tab size in the editor.curOffs
- The offset of the token in the current line.- Returns:
- The length of the token, in characters.
-
isBlankOrAllWhiteSpace
Returns whether a token list isnull
, empty, all whitespace, just comment token(s), or any combination of those.- Parameters:
t
- The token.- Returns:
- Whether the token list starting with that token is
null
, empty, whitespace or comment tokens. - See Also:
-
isBlankOrAllWhiteSpaceWithoutComments
Returns whether a token list isnull
, empty, or all whitespace token(s).- Parameters:
t
- The token.- Returns:
- Whether the token list starting with that token is
null
, empty, or all whitespace token(s). - See Also:
-
tokenToHtml
Generates HTML that renders a token with the style used in an RSTA instance. Note this HTML is not concise. It is a straightforward implementation to be used to generate markup used in copy/paste and dnd scenarios.- Parameters:
textArea
- The text area whose styles to use.token
- The token to get equivalent HTML for.- Returns:
- The HTML.
-