/** * Get the token position that corresponds to the given token and offset. * * @param token * token for which the token-position is being created. * @param offset * offset inside the token. */ public FormatTokenPosition getPosition(TokenItem token, int offset) { return getPosition(token, offset, Position.Bias.Forward); }
/** Get the token position that corresponds to the given token and offset. * @param token token for which the token-position is being created. * @param offset offset inside the token. */ public FormatTokenPosition getPosition(TokenItem token, int offset) { return getPosition(token, offset, Position.Bias.Forward); }
/** Get the next position of the position given by parameters. * It can be either just offset increasing but it can be movement * to the next token for the token boundary. * @return next token-position or null for the EOT position */ public FormatTokenPosition getNextPosition(TokenItem token, int offset, Position.Bias bias) { if (token == null) { // end of chain return null; } else { // regular token offset++; if (offset >= token.getImage().length()) { token = token.getNext(); offset = 0; } return getPosition(token, offset, bias); } }
public FormatTokenPosition getLastPosition() { TokenItem lt = findNonEmptyToken(getLastToken(), true); return (lt == null) ? null : getPosition(lt, lt.getImage().length() - 1); }
public FormatTokenPosition getLastPosition() { TokenItem lt = findNonEmptyToken(getLastToken(), true); return (lt == null) ? null : getPosition(lt, lt.getImage().length() - 1); }
/** * Get the next position of the position given by parameters. It can be * either just offset increasing but it can be movement to the next token * for the token boundary. * * @return next token-position or null for the EOT position */ public FormatTokenPosition getNextPosition(TokenItem token, int offset, Position.Bias bias) { if (token == null) { // end of chain return null; } else { // regular token offset++; if (offset >= token.getImage().length()) { token = token.getNext(); offset = 0; } return getPosition(token, offset, bias); } }
/** Get the previous position of the position given by parameters. * It can be either just offset decreasing but it can be movement * to the previous token for the token boundary. * @return next token-position or null for the first position in the chain */ public FormatTokenPosition getPreviousPosition(TokenItem token, int offset, Position.Bias bias) { FormatTokenPosition ret = null; if (token == null) { // end of chain TokenItem lastToken = findNonEmptyToken(getLastToken(), true); if (lastToken != null) { // regular last token ret = getPosition(lastToken, lastToken.getImage().length() - 1, Position.Bias.Forward); } } else { // regular token offset--; if (offset < 0) { token = token.getPrevious(); if (token != null) { // was first pos in first token ret = getPosition(token, token.getImage().length() - 1, Position.Bias.Forward); } } else { // still inside token ret = getPosition(token, offset, Position.Bias.Forward); } } return ret; }
/** * Get the previous position of the position given by parameters. It can be * either just offset decreasing but it can be movement to the previous * token for the token boundary. * * @return next token-position or null for the first position in the chain */ public FormatTokenPosition getPreviousPosition(TokenItem token, int offset, Position.Bias bias) { FormatTokenPosition ret = null; if (token == null) { // end of chain TokenItem lastToken = findNonEmptyToken(getLastToken(), true); if (lastToken != null) { // regular last token ret = getPosition(lastToken, lastToken.getImage().length() - 1, Position.Bias.Forward); } } else { // regular token offset--; if (offset < 0) { token = token.getPrevious(); if (token != null) { // was first pos in first token ret = getPosition(token, token.getImage().length() - 1, Position.Bias.Forward); } } else { // still inside token ret = getPosition(token, offset, Position.Bias.Forward); } } return ret; }
while (offset < textLen) { if (text.charAt(offset) == '\n') { return getPosition(token, offset); return getPosition(null, 0);
/** Get the ending position of the line. It searches for the new-line * character and returns the position of it * or the position after the last character of the last token * in the chain. * @param pos any token-position on the line. */ public FormatTokenPosition findLineEnd(FormatTokenPosition pos) { TokenItem token = pos.getToken(); int offset = pos.getOffset(); if (token == null) { // end of whole chain is EOL too return pos; } while (true) { String text = token.getImage(); int textLen = text.length(); while (offset < textLen) { if (text.charAt(offset) == '\n') { return getPosition(token, offset); } offset++; } if (token.getNext() == null) { // This is the first token in chain, return end position return getPosition(null, 0); } token = token.getNext(); offset = 0; } }
while (offset < textLen) { if (text.charAt(offset) == '\n') { return getPosition(token, offset);
while (offset < textLen) { if (text.charAt(offset) == '\n') { return getPosition(token, offset);
/** * Get the first EOL in backward direction. The current position is ignored * by the search. * * @return first EOL in backward direction or null if there is no such * token. */ public FormatTokenPosition findPreviousEOL(FormatTokenPosition pos) { pos = getPreviousPosition(pos); if (pos == null) { // was the start position return null; } TokenItem token = pos.getToken(); int offset = pos.getOffset(); while (true) { String text = token.getImage(); while (offset >= 0) { if (text.charAt(offset) == '\n') { return getPosition(token, offset); } offset--; } if (token.getPrevious() == null) { return null; } token = token.getPrevious(); offset = token.getImage().length() - 1; } }
/** Get the first EOL in backward direction. The current position * is ignored by the search. * @return first EOL in backward direction or null if there * is no such token. */ public FormatTokenPosition findPreviousEOL(FormatTokenPosition pos) { pos = getPreviousPosition(pos); if (pos == null) { // was the start position return null; } TokenItem token = pos.getToken(); int offset = pos.getOffset(); while (true) { String text = token.getImage(); while (offset >= 0) { if (text.charAt(offset) == '\n') { return getPosition(token, offset); } offset--; } if (token.getPrevious() == null) { return null; } token = token.getPrevious(); offset = token.getImage().length() - 1; } }
/** Return the first non-whitespace character on the line * or null if there is no non-WS char on the line. */ public FormatTokenPosition findLineFirstNonWhitespace(FormatTokenPosition pos) { pos = findLineStart(pos); TokenItem token = pos.getToken(); int offset = pos.getOffset(); if (token == null) { // no line start, no WS return null; } while (true) { String text = token.getImage(); int textLen = text.length(); while (offset < textLen) { if (text.charAt(offset) == '\n') { return null; } if (!isWhitespace(token, offset)) { return getPosition(token, offset); } offset++; } if (token.getNext() == null) { return null; } token = token.getNext(); offset = 0; } }
/** * Return the first non-whitespace character on the line or null if there is * no non-WS char on the line. */ public FormatTokenPosition findLineFirstNonWhitespace(FormatTokenPosition pos) { pos = findLineStart(pos); TokenItem token = pos.getToken(); int offset = pos.getOffset(); if (token == null) { // no line start, no WS return null; } while (true) { String text = token.getImage(); int textLen = text.length(); while (offset < textLen) { if (text.charAt(offset) == '\n') { return null; } if (!isWhitespace(token, offset)) { return getPosition(token, offset); } offset++; } if (token.getNext() == null) { return null; } token = token.getNext(); offset = 0; } }
return getPosition(token, 0);
return getPosition(token, 0);
return getPosition(token, 0);