private static boolean isWordCharacter(char character) { return Character.isLetterOrDigit(character); }
/** * Checks to see if the specified character is a delimiter. We consider a character a delimiter if * it is anything but a letter or digit. * * @param c the character to test * @return true if it is a delimiter */ private boolean isDelimiter(char c) { return !Character.isLetterOrDigit(c); }
private void doDoubleClick(MouseEvent evt, int line, int offset, int dot) throws BadLocationException { // Ignore empty lines if (getLineLength(line) == 0) return; try { int bracket = TextUtilities.findMatchingBracket(document, Math.max(0, dot - 1)); if (bracket != -1) { int mark = getMarkPosition(); // Hack if (bracket > mark) { bracket++; mark--; } select(mark, bracket); return; } } catch (BadLocationException bl) { bl.printStackTrace(); } // Ok, it's not a bracket... select the word String lineText = getLineText(line); char ch = lineText.charAt(Math.max(0, offset - 1)); String noWordSep = (String) document.getProperty("noWordSep"); if (noWordSep == null) noWordSep = ""; // If the user clicked on a non-letter char, // we select the surrounding non-letters boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1); int wordStart = 0; for (int i = offset - 1; i >= 0; i--) { ch = lineText.charAt(i); if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) { wordStart = i + 1; break; } } int wordEnd = lineText.length(); for (int i = offset; i < lineText.length(); i++) { ch = lineText.charAt(i); if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) { wordEnd = i; break; } } int lineStart = getLineStartOffset(line); select(lineStart + wordStart, lineStart + wordEnd); /* String lineText = getLineText(line); String noWordSep = (String)document.getProperty("noWordSep"); int wordStart = TextUtilities.findWordStart(lineText,offset,noWordSep); int wordEnd = TextUtilities.findWordEnd(lineText,offset,noWordSep); int lineStart = getLineStartOffset(line); select(lineStart + wordStart,lineStart + wordEnd); */ }
public void setPattern(String globPattern) { char[] gPat = globPattern.toCharArray(); char[] rPat = new char[gPat.length * 2]; boolean isWin32 = (File.separatorChar == '\\'); boolean inBrackets = false; int j = 0; this.globPattern = globPattern; if (isWin32) { // On windows, a pattern ending with *.* is equal to ending with * int len = gPat.length; if (globPattern.endsWith("*.*")) { len -= 2; } for (int i = 0; i < len; i++) { switch (gPat[i]) { case '*': rPat[j++] = '.'; rPat[j++] = '*'; break; case '?': rPat[j++] = '.'; break; case '\\': rPat[j++] = '\\'; rPat[j++] = '\\'; break; default: if ("+()^$.{}[]".indexOf(gPat[i]) >= 0) { rPat[j++] = '\\'; } rPat[j++] = gPat[i]; break; } } } else { for (int i = 0; i < gPat.length; i++) { switch (gPat[i]) { case '*': if (!inBrackets) { rPat[j++] = '.'; } rPat[j++] = '*'; break; case '?': rPat[j++] = inBrackets ? '?' : '.'; break; case '[': inBrackets = true; rPat[j++] = gPat[i]; if (i < gPat.length - 1) { switch (gPat[i + 1]) { case '!': case '^': rPat[j++] = '^'; i++; break; case ']': rPat[j++] = gPat[++i]; break; } } break; case ']': rPat[j++] = gPat[i]; inBrackets = false; break; case '\\': if (i == 0 && gPat.length > 1 && gPat[1] == '~') { rPat[j++] = gPat[++i]; } else { rPat[j++] = '\\'; if (i < gPat.length - 1 && "*?[]".indexOf(gPat[i + 1]) >= 0) { rPat[j++] = gPat[++i]; } else { rPat[j++] = '\\'; } } break; default: // if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) { if (!Character.isLetterOrDigit(gPat[i])) { rPat[j++] = '\\'; } rPat[j++] = gPat[i]; break; } } } this.pattern = Pattern.compile(new String(rPat, 0, j), Pattern.CASE_INSENSITIVE); }