private static boolean isWhitespace(Document document, int startOffset, int endOffset) throws BadLocationException { CharSequence chars = DocumentUtilities.getText(document, startOffset, endOffset - startOffset); for(int i = 0; i < chars.length(); i++) { if (!Character.isWhitespace(chars.charAt(i))) { return false; } } return true; }
public ModRootElement(Document doc) { super(doc); docText = DocumentUtilities.getText(doc); doc.putProperty(NAME, this); }
public void setStartOffset(int offset) { currentWord = null; currentStartOffset = (-1); CharSequence content = DocumentUtilities.getText(doc); while (offset > 0 && offset < content.length()) { if (!Character.isLetter(content.charAt(offset))) { break; } offset--; } this.nextSearchOffset = offset; FileObject fileObject = FileUtil.getConfigFile ("Spellcheckers/Plain"); Boolean b = (Boolean) fileObject.getAttribute ("Hidden"); hidden = Boolean.TRUE.equals (b); }
@Override public int getIdentifierEnd(Document doc, int offset, boolean backward) { DocumentCharacterAcceptor characterAcceptor = DocumentCharacterAcceptor.get(doc); CharSequence docText = DocumentUtilities.getText(doc); if (backward) { while (--offset >= 0 && characterAcceptor.isIdentifier(docText.charAt(offset))) { } return offset + 1; } else { int docTextLen = docText.length(); while (offset < docTextLen && characterAcceptor.isIdentifier(docText.charAt(offset))) { offset++; } return offset; } }
public static int getPreviousNonNewline(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getPreviousNonNewline(docText, offset, 0); }
/** * Tests whether the line at the given offset contains no characters except the ending new-line. * @param doc document to operate on * @param offset position anywhere on the tested line * @return whether the line is empty or not */ public static boolean isLineEmpty(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.isLineEmpty(docText, offset); }
/** * Get the word at given offset. * @param doc document to operate on * @param wordStartOffset offset of word start. * @return word starting at offset. */ public static String getWord(@NonNull LineDocument doc, int wordStartOffset) throws BadLocationException { checkOffsetValid(doc, wordStartOffset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getWord(docText, classifier, wordStartOffset).toString(); }
public static int getPreviousWordEnd(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getPreviousWordEnd(docText, classifier, offset); }
public static int getWordEnd(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getWordEnd(docText, classifier, offset); }
public static int getWordStart(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getWordStart(docText, classifier, offset); }
public static int getNextWordStart(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getNextWordStart(docText, classifier, offset); }
public static int getNextNonNewline(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getNextNonNewline(docText, offset, doc.getLength() + 1); }
private boolean isInComment(Document doc, int offset) { CharSequence text = DocumentUtilities.getText(doc); //shared instance, low cost int lastCommentStartIndex = CharSequenceUtilities.lastIndexOf(text, commentHandler.getCommentStartDelimiter(), offset); int lastCommentEndIndex = CharSequenceUtilities.lastIndexOf(text, commentHandler.getCommentEndDelimiter(), offset); return lastCommentStartIndex > -1 && (lastCommentStartIndex > lastCommentEndIndex || lastCommentEndIndex == -1); }
/** * Generalized posWithingString to any token and delimiting * character. It works for tokens are delimited by *quote* and * extend up to the other *quote* or whitespace in case of an * incomplete token. * @param doc the document * @param dotPos position to be tested */ static boolean posWithinQuotes(BaseDocument doc, int dotPos, char quote, CppTokenId[] tokenIDs) { TokenSequence<TokenId> cppTS = cppTokenSequence(doc, dotPos, true); if (cppTS != null && matchIDs(cppTS.token().id(), tokenIDs)) { return (dotPos - cppTS.offset() == 1 || DocumentUtilities.getText(doc).charAt(dotPos - 1) != quote); } return false; }
/** * Generalized posWithingString to any token and delimiting * character. It works for tokens are delimited by *quote* and * extend up to the other *quote* or whitespace in case of an * incomplete token. * @param doc the document * @param dotPos position to be tested */ private boolean posWithinQuotes(BaseDocument doc, int dotPos, char quote, FortranTokenId[] tokenIDs) { TokenSequence<FortranTokenId> cppTS = getTokenSequence(doc, dotPos); if (cppTS != null && matchIDs(cppTS.token().id(), tokenIDs)) { return (dotPos - cppTS.offset() == 1 || DocumentUtilities.getText(doc).charAt(dotPos - 1) != quote); } return false; }
/** * Get first non-whitespace character in document in forward direction. * * @param doc document to operate on * @param offset offset of first character to examine for WS. * @param limitOffset the offset of the last character to examine for WS. * @return position of the next non-WS character or -1 if not found. */ public static int getPreviousNonWhitespace(@NonNull LineDocument doc, int offset, int limitOffset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getPreviousNonWhitespace(docText, classifier, offset, limitOffset); }
/** * Get start of a previous word in backward direction. * * @param doc non-null document. * @param offset >= 0 offset in document. * @return previous word boundary offset. * @since 1.4 */ public static int getPreviousWordStart(@NonNull LineDocument doc, int offset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getPreviousWordStart(docText, classifier, offset); }
/** * Get first whitespace character in document in forward direction. * * @param doc document to operate on * @param offset position in document where to start searching * @param limitOffset offset above the last character to examine for WS. * @return position of the next WS character or -1 if not found. */ public static int getNextWhitespace(@NonNull LineDocument doc, int offset, int limitOffset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getNextWhitespace(docText, classifier, offset, limitOffset); }
/** * Get first non-whitespace character in document in forward direction. * * @param doc document to operate on * @param offset offset of first character to examine for WS. * @param limitOffset offset above the last character to examine for WS. * @return position of the next non-WS character or -1 if not found. */ public static int getNextNonWhitespace(@NonNull LineDocument doc, int offset, int limitOffset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getNextNonWhitespace(docText, classifier, offset, limitOffset); }
/** * Get first whitespace character in document in backward direction. * * @param doc document to operate on * @param offset offset above first character to examine for WS. * @param limitOffset offset of the last character (in backward direction) to examine for WS. * @return position of the previous WS character or -1 if not found. */ public static int getPreviousWhitespace(@NonNull LineDocument doc, int offset, int limitOffset) throws BadLocationException { checkOffsetValid(doc, offset); CharClassifier classifier = getValidClassifier(doc); CharSequence docText = DocumentUtilities.getText(doc); return TextSearchUtils.getPreviousWhitespace(docText, classifier, offset, limitOffset); }