public int findInsideBlocks(Finder finder, int startPos, int endPos, int[] blocks) throws BadLocationException { boolean fwd = (startPos <= endPos); if (fwd) { for (int i = 0; i < blocks.length; i += 2) { int pos = doc.find(finder, blocks[i], blocks[i + 1]); if (pos >= 0) { return pos; } } } else { // find backward for (int i = blocks.length - 2; i >= 0; i -= 2) { int pos = doc.find(finder, blocks[i + 1], blocks[i]); if (pos >= 0) { return pos; } } } return -1; }
public static int getPreviousWord(BaseDocument doc, int offset) throws BadLocationException { Finder prevWordFinder = (Finder)doc.getProperty(SettingsNames.PREVIOUS_WORD_FINDER); offset = doc.find(prevWordFinder, offset, 0); if (offset < 0) { offset = 0; } return offset; }
public static int getWordStart(BaseDocument doc, int offset) throws BadLocationException { return doc.find(new FinderFactory.PreviousWordBwdFinder(doc, false, true), offset, 0); }
/** Get first white character in document in forward direction * @param doc document to operate on * @param offset position in document where to start searching * @param limitPos position in document (greater or equal than offset) where * the search will stop reporting unsuccessful search by returning -1 * @return position of the first non-white character or -1 */ public static int getFirstWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException { return doc.find(new FinderFactory.WhiteFwdFinder(doc), offset, limitPos); }
/** Get first non-white character in document in forward direction * @param doc document to operate on * @param offset position in document where to start searching * @param limitPos position in document (greater or equal than offset) where * the search will stop reporting unsuccessful search by returning -1 * @return position of the first non-white character or -1 */ public static int getFirstNonWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException { return doc.find(new FinderFactory.NonWhiteFwdFinder(doc), offset, limitPos); }
public static int getPreviousWord(BaseDocument doc, int offset) throws BadLocationException { Finder prevWordFinder = (Finder) doc.getProperty(SettingsNames.PREVIOUS_WORD_FINDER); offset = doc.find(prevWordFinder, offset, 0); if (offset < 0) { offset = 0; } return offset; }
public static int getWordEnd(BaseDocument doc, int offset) throws BadLocationException { return doc.find(new FinderFactory.NextWordFwdFinder(doc, false, true), offset, -1); }
/** Get first non-white character in document in backward direction. * The character right before the character at position offset will * be searched as first. * @param doc document to operate on * @param offset position in document where to start searching * @param limitPos position in document (lower or equal than offset) where * the search will stop reporting unsuccessful search by returning -1 * @return position of the first non-white character or -1 */ public static int getFirstNonWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException { return doc.find(new FinderFactory.NonWhiteBwdFinder(doc), offset, limitPos); }
/** * Get first white character in document in forward direction * * @param doc * document to operate on * @param offset * position in document where to start searching * @param limitPos * position in document (greater or equal than offset) where the * search will stop reporting unsuccessful search by returning -1 * @return position of the first non-white character or -1 */ public static int getFirstWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException { return doc.find(new FinderFactory.WhiteFwdFinder(doc), offset, limitPos); }
/** Get first white character in document in backward direction. * The character right before the character at position offset will * be searched as first. * @param doc document to operate on * @param offset position in document where to start searching * @param limitPos position in document (lower or equal than offset) where * the search will stop reporting unsuccessful search by returning -1 * @return position of the first white character or -1 */ public static int getFirstWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException { return doc.find(new FinderFactory.WhiteBwdFinder(doc), offset, limitPos); }
/** * Get first non-white character in document in forward direction * * @param doc * document to operate on * @param offset * position in document where to start searching * @param limitPos * position in document (greater or equal than offset) where the * search will stop reporting unsuccessful search by returning -1 * @return position of the first non-white character or -1 */ public static int getFirstNonWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException { return doc.find(new FinderFactory.NonWhiteFwdFinder(doc), offset, limitPos); }
/** * Get first non-white character in document in backward direction. The * character right before the character at position offset will be searched * as first. * * @param doc * document to operate on * @param offset * position in document where to start searching * @param limitPos * position in document (lower or equal than offset) where the * search will stop reporting unsuccessful search by returning -1 * @return position of the first non-white character or -1 */ public static int getFirstNonWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException { return doc.find(new FinderFactory.NonWhiteBwdFinder(doc), offset, limitPos); }
public static int getWordStart(BaseDocument doc, int offset) throws BadLocationException { int docLen = doc.getLength(); return doc.find(new FinderFactory.PreviousWordBwdFinder(doc, false, true), offset, 0); }
public static int getNextWord(BaseDocument doc, int offset) throws BadLocationException { Finder nextWordFinder = (Finder)doc.getProperty(SettingsNames.NEXT_WORD_FINDER); offset = doc.find(nextWordFinder, offset, -1); if (offset < 0) { offset = doc.getLength(); } return offset; }
public static int getNextWord(BaseDocument doc, int offset) throws BadLocationException { Finder nextWordFinder = (Finder) doc.getProperty(SettingsNames.NEXT_WORD_FINDER); offset = doc.find(nextWordFinder, offset, -1); if (offset < 0) { offset = doc.getLength(); } return offset; }
public static int getWordEnd(BaseDocument doc, int offset) throws BadLocationException { int ret = doc.find(new FinderFactory.NextWordFwdFinder(doc, false, true), offset, -1); return (ret > 0) ? ret : doc.getLength(); }
int[] getBlocks(int[] blocks, BaseDocument doc, int startPos, int endPos) throws BadLocationException { FinderFactory.BlocksFinder ppf = getBlocksFinder(doc, null); if (ppf == null) { // not yet assigned return blocks; } synchronized (ppf) { ppf.setBlocks(blocks); doc.find(ppf, startPos, endPos); return ppf.getBlocks(); } }
int[] getBlocks(int[] blocks, BaseDocument doc, int startPos, int endPos) throws BadLocationException { FinderFactory.BlocksFinder ppf = getBlocksFinder(doc, null); if (ppf == null) { // not yet assigned return blocks; } synchronized (ppf) { ppf.setBlocks(blocks); doc.find(ppf, startPos, endPos); return ppf.getBlocks(); } }
/** * Tests whether the line contains only whitespace characters. * * @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 isRowWhite(BaseDocument doc, int offset) throws BadLocationException { offset = doc.find(new FinderFactory.NonWhiteFwdFinder(doc), doc.op.getBOL(offset), doc.op.getEOL(offset)); return (offset == -1); }
/** Tests whether the line contains only whitespace characters. * @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 isRowWhite(BaseDocument doc, int offset) throws BadLocationException { Element lineElement = doc.getParagraphElement(offset); offset = doc.find(new FinderFactory.NonWhiteFwdFinder(doc), lineElement.getStartOffset(), lineElement.getEndOffset() - 1); return (offset == -1); }