コード例 #1
1
ファイル: EditorServer.java プロジェクト: amarala/recoled
  public String getTextForGesture(long parId, Point topLeft, Point bottomRight) {

    try {
      Paragraph p = lockManager.getParFromId(parId);

      int parY = documentPanel.textPane.modelToView(p.getOffset()).y;

      topLeft.y = topLeft.y + parY;
      bottomRight.y = bottomRight.y + parY;

      int startOffset = documentPanel.textPane.viewToModel(topLeft);
      int endOffset = documentPanel.textPane.viewToModel(bottomRight);

      while (startOffset > 0
          && Character.isLetterOrDigit((document.getText(startOffset - 1, 1).charAt(0))))
        startOffset--;

      while (endOffset < document.getLength()
          && Character.isLetterOrDigit((document.getText(endOffset, 1).charAt(0)))) endOffset++;

      String text = document.getText(startOffset, endOffset - startOffset);
      return text;
    } catch (Exception e) {
      System.out.println("EditorClient: addGestureAction. error identifying text");
      e.printStackTrace();
      return "";
    }

    // return "PLACEBO";
  }
コード例 #2
0
  public static boolean isPalindrome(String s) {
    String n = s.toLowerCase();

    int i = 0, j = n.length() - 1;

    while (i < j) {
      char b = n.charAt(i);
      char e = n.charAt(j);
      if (Character.isLetterOrDigit(b)) {
        if (Character.isLetterOrDigit(e)) {
          System.out.println(b + " " + e);
          if (b != e) {
            return false;
          } else {
            i++;
            j--;
          }
        } else {
          j--;
        }
      } else {
        i++;
      }
    }
    return true;
  }
コード例 #3
0
  protected int seekNextCaretLocation(int pos, boolean forward) {

    int dir = forward ? 1 : -1;
    int e = forward ? textLength : 0;
    if (pos == textLength) {
      --pos;
    }
    char prevChar = text[pos];
    while (pos != e && Character.isSpaceChar(prevChar)) {
      prevChar = text[pos += dir];
    }

    if (smartCaret) {
      for (int i = pos; i != e; i += dir) {
        char curChar = text[i];
        boolean caze = Character.isUpperCase(curChar) != Character.isUpperCase(prevChar);
        if (caze
            || Character.isSpaceChar(curChar) != Character.isSpaceChar(prevChar)
            || Character.isLetterOrDigit(curChar) != Character.isLetterOrDigit(prevChar)) {
          if ((pos + dir) != i || !Character.isLetterOrDigit(curChar)) {
            return i + (smartCaretCase && caze && Character.isUpperCase(prevChar) ? -dir : 0);
          }
        }
        prevChar = curChar;
      }
    }
    for (int i = pos; i != e; i += dir) {
      char curChar = text[i];
      if (Character.isSpaceChar(curChar) != Character.isSpaceChar(prevChar)) {
        return i;
      }
    }
    return forward ? textLength : 0;
  }
コード例 #4
0
  private int findNext(int pos, String txt, String value) {
    int ix = forwardButton.isSelected() ? txt.indexOf(value, pos) : txt.lastIndexOf(value, pos);

    if (selectedLinesButton.isSelected()
        && (ix < target.getSelectionStart() || ix > target.getSelectionEnd())) {
      ix = -1;
    }

    if (wholeWordCheck.isSelected()) {
      while (ix != -1
          && ((ix > 0 && Character.isLetterOrDigit(txt.charAt(ix - 1)))
              || (ix < txt.length() - value.length() - 1
                  && Character.isLetterOrDigit(txt.charAt(ix + value.length()))))) {
        ix = forwardButton.isSelected() ? ++ix : --ix;
        ix = forwardButton.isSelected() ? txt.indexOf(value, ix) : txt.lastIndexOf(value, ix);
      }
    }

    if (ix == -1 && wrapCheck.isSelected()) {
      if (forwardButton.isSelected() && pos > 0) {
        return findNext(0, txt, value);
      } else if (backwardButton.isSelected() && pos < txt.length() - 1) {
        return findNext(txt.length() - 1, txt, value);
      }
    }

    return ix;
  }
コード例 #5
0
  private int findalias(String sentence, int position) {

    int i = position - 1;
    int s = 0;

    while (i > 0) {
      char c = sentence.charAt(i);
      if (s == 0) {
        if (c == '.') {
          s = 1;
        } else {
          return -1;
        }
      } else if (s == 1) {
        if (Character.isLetterOrDigit(c)) {
          s = 2;
        } else {
          return -1;
        }
      } else if (s == 2) {
        if (!Character.isLetterOrDigit(c)) {
          if (Character.isWhitespace(c) || c == ')' || c == '(') {
            return i + 1;
          } else {
            return -1;
          }
        }
      }
      i--;
    }
    return -1;
  }
コード例 #6
0
  /**
   * Returns the end of the word at the given offset.
   *
   * @param textArea The text area.
   * @param offs The offset into the text area's content.
   * @return The end offset of the word.
   * @throws BadLocationException If <code>offs</code> is invalid.
   * @see #getWordStart(RSyntaxTextArea, int)
   */
  public static int getWordEnd(RSyntaxTextArea textArea, int offs) throws BadLocationException {

    Document doc = textArea.getDocument();
    int endOffs = textArea.getLineEndOffsetOfCurrentLine();
    int lineEnd = Math.min(endOffs, doc.getLength());
    if (offs == lineEnd) { // End of the line.
      return offs;
    }

    String s = doc.getText(offs, lineEnd - offs - 1);
    if (s != null && s.length() > 0) { // Should always be true
      int i = 0;
      int count = s.length();
      char ch = s.charAt(i);
      if (Character.isWhitespace(ch)) {
        while (i < count && Character.isWhitespace(s.charAt(i++))) ;
      } else if (Character.isLetterOrDigit(ch)) {
        while (i < count && Character.isLetterOrDigit(s.charAt(i++))) ;
      } else {
        i = 2;
      }
      offs += i - 1;
    }

    return offs;
  }
コード例 #7
0
  /**
   * Returns the start of the word at the given offset.
   *
   * @param textArea The text area.
   * @param offs The offset into the text area's content.
   * @return The start offset of the word.
   * @throws BadLocationException If <code>offs</code> is invalid.
   * @see #getWordEnd(RSyntaxTextArea, int)
   */
  public static int getWordStart(RSyntaxTextArea textArea, int offs) throws BadLocationException {

    Document doc = textArea.getDocument();
    Element line = getLineElem(doc, offs);
    if (line == null) {
      throw new BadLocationException("No word at " + offs, offs);
    }

    int lineStart = line.getStartOffset();
    if (offs == lineStart) { // Start of the line.
      return offs;
    }

    int endOffs = Math.min(offs + 1, doc.getLength());
    String s = doc.getText(lineStart, endOffs - lineStart);
    if (s != null && s.length() > 0) {
      int i = s.length() - 1;
      char ch = s.charAt(i);
      if (Character.isWhitespace(ch)) {
        while (i > 0 && Character.isWhitespace(s.charAt(i - 1))) {
          i--;
        }
        offs = lineStart + i;
      } else if (Character.isLetterOrDigit(ch)) {
        while (i > 0 && Character.isLetterOrDigit(s.charAt(i - 1))) {
          i--;
        }
        offs = lineStart + i;
      }
    }

    return offs;
  }
コード例 #8
0
  private void handleNoSelection(Editor editor) {
    CaretModel caretModel = editor.getCaretModel();
    Document doc = editor.getDocument();
    if ((caretModel == null) || (doc == null) || (doc.getTextLength() == 0)) {
      return;
    }

    char[] allChars = doc.getChars();
    int maxOffset = allChars.length;

    int startOffset = caretModel.getOffset();

    while ((startOffset < maxOffset) && (!Character.isLetterOrDigit(allChars[startOffset]))) {
      startOffset++;
    }

    StringBuffer word = new StringBuffer();
    int i = startOffset;
    while ((i < maxOffset) && (Character.isLetterOrDigit(allChars[i]))) {
      word.append(allChars[i]);

      i++;
    }

    if (word.length() > 0) {
      this.m_transformer.transform(word);
      int newOffset = startOffset + word.length();
      doc.replaceString(startOffset, newOffset, word.toString());

      caretModel.moveToOffset(newOffset);
    }
  }
コード例 #9
0
ファイル: Solution.java プロジェクト: linkinwong/code
 public boolean isPalindrome(String s) {
   if (s.length() == 0) return true;
   // System.out.println(cs);
   int i = 0, j = s.length() - 1;
   boolean flag = true;
   while (i < j) {
     // System.out.println(s.charAt(i)+" vs " + s.charAt(j)  );
     if (Character.isLetterOrDigit(s.charAt(i)) == false) {
       // System.out.println("i is not alphanumeric " + s.charAt(i)  );
       i++;
       continue;
     }
     if (Character.isLetterOrDigit(s.charAt(j)) == false) {
       // System.out.println("j is not alphanumeric:" + s.charAt(j)  );
       j--;
       continue;
     }
     if (s.charAt(i) == s.charAt(j) || Math.abs(s.charAt(i) - s.charAt(j)) == 32) {
       if ((Character.isDigit(s.charAt(i)) && Character.isLetter(s.charAt(j)))
           || (Character.isDigit(s.charAt(j)) && Character.isLetter(s.charAt(i)))) {
         flag = false;
         break;
       }
       flag = true;
       i++;
       j--;
     } else {
       flag = false;
       // System.out.println(s.charAt(i)+" vs " + s.charAt(j)  );
       break;
     }
   }
   System.out.println(flag);
   return flag;
 }
コード例 #10
0
  private String findBestLongForm(String shortForm, String longForm) {
    int sIndex;
    int lIndex;
    char currChar;

    sIndex = shortForm.length() - 1;
    lIndex = longForm.length() - 1;
    for (; sIndex >= 0; sIndex--) {
      currChar = Character.toLowerCase(shortForm.charAt(sIndex));
      if (!Character.isLetterOrDigit(currChar)) {
        continue;
      }
      while (((lIndex >= 0) && (Character.toLowerCase(longForm.charAt(lIndex)) != currChar))
          || ((sIndex == 0)
              && (lIndex > 0)
              && (Character.isLetterOrDigit(longForm.charAt(lIndex - 1))))) {
        lIndex--;
      }
      if (lIndex < 0) {
        return null;
      }
      lIndex--;
    }
    lIndex = longForm.lastIndexOf(" ", lIndex) + 1;
    return longForm.substring(lIndex);
  }
コード例 #11
0
  public static String getExpansionByHearstAlgorithm(String shortForm, String longForm) {
    int sIndex;
    int lIndex;
    char currChar;

    sIndex = shortForm.length() - 1;
    lIndex = longForm.length() - 1;

    for (; sIndex >= 0; sIndex--) {
      currChar = Character.toLowerCase(shortForm.charAt(sIndex));
      if (!Character.isLetterOrDigit(currChar)) continue;

      while (((lIndex >= 0) && (Character.toLowerCase(longForm.charAt(lIndex)) != currChar))
          || ((sIndex == 0)
              && (lIndex > 0)
              && (Character.isLetterOrDigit(longForm.charAt(lIndex - 1))))) lIndex--;
      if (lIndex < 0) return "";
      lIndex--;
    }

    lIndex = longForm.lastIndexOf(" ", lIndex) + 1;
    longForm = longForm.substring(lIndex);

    return longForm;
  }
コード例 #12
0
ファイル: NodeCounter.java プロジェクト: tnndwc/Java8-7
  // format == null assumed here
  private final void setTokens(final String format) {
    if ((_format != null) && (format.equals(_format))) { // has already been set
      return;
    }
    _format = format;
    // reset
    final int length = _format.length();
    boolean isFirst = true;
    _separFirst = true;
    _separLast = false;
    _nSepars = 0;
    _nFormats = 0;
    _separToks.clear();
    _formatToks.clear();

    /*
     * Tokenize the format string into alphanumeric and non-alphanumeric
     * tokens as described in M. Kay page 241.
     */
    for (int j = 0, i = 0; i < length; ) {
      char c = format.charAt(i);
      for (j = i; Character.isLetterOrDigit(c); ) {
        if (++i == length) break;
        c = format.charAt(i);
      }
      if (i > j) {
        if (isFirst) {
          _separToks.addElement(".");
          isFirst = _separFirst = false;
        }
        _formatToks.addElement(format.substring(j, i));
      }

      if (i == length) break;

      c = format.charAt(i);
      for (j = i; !Character.isLetterOrDigit(c); ) {
        if (++i == length) break;
        c = format.charAt(i);
        isFirst = false;
      }
      if (i > j) {
        _separToks.addElement(format.substring(j, i));
      }
    }

    _nSepars = _separToks.size();
    _nFormats = _formatToks.size();
    if (_nSepars > _nFormats) _separLast = true;

    if (_separFirst) _nSepars--;
    if (_separLast) _nSepars--;
    if (_nSepars == 0) {
      _separToks.insertElementAt(".", 1);
      _nSepars++;
    }
    if (_separFirst) _nSepars++;
  }
コード例 #13
0
  // Converts < EOF >, < 'EOF' >, etc to <EOF>
  private String createReadinString(char[] array, int start, int len) {
    int idx1 = start;
    int idx2 = start + len - 1;

    while ((idx1 <= idx2) && (!Character.isLetterOrDigit(array[idx1]))) idx1++;

    while ((idx1 <= idx2) && (!Character.isLetterOrDigit(array[idx2]))) idx2--;

    return new String(array, idx1, idx2 - idx1 + 1);
  }
コード例 #14
0
ファイル: SQLDeArger.java プロジェクト: veinrein/usemon
 private boolean isWordBoundary(char currentCh, char nextCh) {
   // word boundaries are special puncutation, when not in a string.
   // select * from table where key=100
   // first part of conditional would be triggered with convert(200. if currentchar was '('
   // 2nd part: select *, convert(char(20)... from. if characther is 't' of select or 't'
   // of 'convert'
   return (isPunctuation(currentCh) && Character.isLetterOrDigit(nextCh))
       || (!isInString()
           && (Character.isWhitespace(nextCh) || !Character.isLetterOrDigit(nextCh)));
 }
コード例 #15
0
 /**
  * @param s A string
  * @return Whether the string is a valid palindrome
  */
 public boolean isPalindrome(String s) {
   // Write your code here
   int i = 0;
   int j = s.length() - 1;
   while (i < j)
     if (!Character.isLetterOrDigit(s.charAt(i))) i++;
     else if (!Character.isLetterOrDigit(s.charAt(j))) j--;
     else if (Character.toLowerCase(s.charAt(i++)) != Character.toLowerCase(s.charAt(j--)))
       return false;
   return true;
 }
コード例 #16
0
ファイル: VexWidgetImpl.java プロジェクト: kingargyle/vex
  public void moveToPreviousWord(boolean select) {
    VEXDocument doc = this.getDocument();
    int offset = this.getCaretOffset();
    while (offset > 1 && !Character.isLetterOrDigit(doc.getCharacterAt(offset - 1))) {
      offset--;
    }

    while (offset > 1 && Character.isLetterOrDigit(doc.getCharacterAt(offset - 1))) {
      offset--;
    }

    this.moveTo(offset, select);
  }
コード例 #17
0
ファイル: JavaTextArea.java プロジェクト: qicny/processing
  /**
   * Retrieves the word on which the mouse pointer is present
   *
   * @param evt - the MouseEvent which triggered this method
   */
  private String fetchPhrase(MouseEvent evt) {
    Messages.log("--handle Mouse Right Click--");
    int off = xyToOffset(evt.getX(), evt.getY());
    if (off < 0) return null;
    int line = getLineOfOffset(off);
    if (line < 0) return null;
    String s = getLineText(line);
    if (s == null) return null;
    else if (s.length() == 0) return null;
    else {
      int x = xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
      int xLS = off - getLineStartNonWhiteSpaceOffset(line);
      Messages.log("x=" + x);
      if (x < 0 || x >= s.length()) return null;
      String word = s.charAt(x) + "";
      if (s.charAt(x) == ' ') return null;
      if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_' || s.charAt(x) == '$'))
        return null;
      int i = 0;
      while (true) {
        i++;
        if (x1 >= 0 && x1 < s.length()) {
          if (Character.isLetter(s.charAt(x1)) || s.charAt(x1) == '_') {
            word = s.charAt(x1--) + word;
            xLS--;
          } else x1 = -1;
        } else x1 = -1;

        if (x2 >= 0 && x2 < s.length()) {
          if (Character.isLetterOrDigit(s.charAt(x2)) || s.charAt(x2) == '_' || s.charAt(x2) == '$')
            word = word + s.charAt(x2++);
          else x2 = -1;
        } else x2 = -1;

        if (x1 < 0 && x2 < 0) break;
        if (i > 200) {
          // time out!
          break;
        }
      }
      if (Character.isDigit(word.charAt(0))) {
        return null;
      }
      Messages.log("Mouse click, word: " + word.trim());
      ASTGenerator astGenerator = editor.getErrorChecker().getASTGenerator();
      synchronized (astGenerator) {
        astGenerator.setLastClickedWord(line, word, xLS);
      }
      return word.trim();
    }
  }
コード例 #18
0
ファイル: VexWidgetImpl.java プロジェクト: kingargyle/vex
  public void moveToNextWord(boolean select) {
    VEXDocument doc = this.getDocument();
    int n = doc.getLength() - 1;
    int offset = this.getCaretOffset();
    while (offset < n && !Character.isLetterOrDigit(doc.getCharacterAt(offset))) {
      offset++;
    }

    while (offset < n && Character.isLetterOrDigit(doc.getCharacterAt(offset))) {
      offset++;
    }

    this.moveTo(offset, select);
  }
コード例 #19
0
ファイル: Exactype.java プロジェクト: walles/exactype
  /**
   * To remove the last word, how many chars would that be?
   *
   * @param before Text before cursor
   * @return How many characters we should remove
   */
  private int countCharsToDelete(CharSequence before) {
    int index = before.length() - 1;

    // Count non-alphanumeric characters from the end
    while (index >= 0 && !Character.isLetterOrDigit(before.charAt(index))) {
      index--;
    }

    // Count the number of alphanumeric characters preceding those
    while (index >= 0 && Character.isLetterOrDigit(before.charAt(index))) {
      index--;
    }

    return before.length() - 1 - index;
  }
コード例 #20
0
ファイル: TextGrid.java プロジェクト: pepijnve/ditaa
 public boolean isBullet(Cell cell) {
   char c = get(cell);
   return (c == 'o' || c == '*')
       && isBlank(cell.getEast())
       && isBlank(cell.getWest())
       && Character.isLetterOrDigit(get(cell.getEast().getEast()));
 }
コード例 #21
0
ファイル: Config.java プロジェクト: liz-zorzo-movile/jgit
  private static String readSectionName(final StringReader in) throws ConfigInvalidException {
    final StringBuilder name = new StringBuilder();
    for (; ; ) {
      int c = in.read();
      if (c < 0) throw new ConfigInvalidException(JGitText.get().unexpectedEndOfConfigFile);

      if (']' == c) {
        in.reset();
        break;
      }

      if (' ' == c || '\t' == c) {
        for (; ; ) {
          c = in.read();
          if (c < 0) throw new ConfigInvalidException(JGitText.get().unexpectedEndOfConfigFile);

          if ('"' == c) {
            in.reset();
            break;
          }

          if (' ' == c || '\t' == c) continue; // Skipped...
          throw new ConfigInvalidException(
              MessageFormat.format(JGitText.get().badSectionEntry, name));
        }
        break;
      }

      if (Character.isLetterOrDigit((char) c) || '.' == c || '-' == c) name.append((char) c);
      else
        throw new ConfigInvalidException(
            MessageFormat.format(JGitText.get().badSectionEntry, name));
    }
    return name.toString();
  }
コード例 #22
0
ファイル: TextUtilities.java プロジェクト: TouK/soapuii
  /**
   * Locates the end of the word at the specified position.
   *
   * @param line The text
   * @param pos The position
   */
  public static int findWordEnd(String line, int pos, String noWordSep) {
    char ch = line.charAt(pos);

    if (noWordSep == null) noWordSep = "";
    boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1);

    int wordEnd = line.length();
    for (int i = pos; i < line.length(); i++) {
      ch = line.charAt(i);
      if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) {
        wordEnd = i;
        break;
      }
    }
    return wordEnd;
  }
コード例 #23
0
  static String escapeFile(String path) {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < path.length(); i++) {
      char c = path.charAt(i);
      if (Character.isLetterOrDigit(c)) {
        sb.append(c);
      } else {
        switch (c) {
          case '.':
          case '-':
          case '_':
          case '/':
          case ':':
            sb.append(c);
            break;

          default:
            throw new IllegalArgumentException("Don't know how to escape character: " + ((int) c));
        }
      }
    }

    return sb.toString();
  }
コード例 #24
0
  public static String escapeJavaScript(String javaScript) {

    StringBuilder stringBuilder = new StringBuilder();
    char[] javaScriptCharArray = javaScript.toCharArray();

    for (char character : javaScriptCharArray) {

      if ((character > 255) || Character.isLetterOrDigit(character)) {

        stringBuilder.append(character);
      } else {
        stringBuilder.append(JAVA_SCRIPT_HEX_PREFIX);

        String hexString = toHexString(character);

        if (hexString.length() == 1) {
          stringBuilder.append(StringPool.ASCII_TABLE[48]);
        }

        stringBuilder.append(hexString);
      }
    }

    if (stringBuilder.length() != javaScript.length()) {
      javaScript = stringBuilder.toString();
    }

    return javaScript;
  }
コード例 #25
0
  static {
    _unescapeMap.put("lt", "<");
    _unescapeMap.put("gt", ">");
    _unescapeMap.put("amp", "&");
    _unescapeMap.put("rsquo", "\u2019");
    _unescapeMap.put("#34", "\"");
    _unescapeMap.put("#39", "'");
    _unescapeMap.put("#40", "(");
    _unescapeMap.put("#41", ")");
    _unescapeMap.put("#44", ",");
    _unescapeMap.put("#35", "#");
    _unescapeMap.put("#37", "%");
    _unescapeMap.put("#59", ";");
    _unescapeMap.put("#61", "=");
    _unescapeMap.put("#43", "+");
    _unescapeMap.put("#45", "-");

    for (int i = 0; i < _VALID_CHARS.length; i++) {
      if (Character.isLetterOrDigit(i)) {
        _VALID_CHARS[i] = true;
      }
    }

    _VALID_CHARS['-'] = true;
    _VALID_CHARS['_'] = true;
  }
コード例 #26
0
ファイル: Utils.java プロジェクト: canhpv/ecms
 /**
  * Clean string.
  *
  * @param str the str
  * @return the string
  */
 public static String cleanString(String str) {
   Transliterator accentsconverter =
       Transliterator.getInstance("Latin; NFD; [:Nonspacing Mark:] Remove; NFC;");
   str = accentsconverter.transliterate(str);
   // the character ? seems to not be changed to d by the transliterate
   // function
   StringBuffer cleanedStr = new StringBuffer(str.trim());
   // delete special character
   for (int i = 0; i < cleanedStr.length(); i++) {
     char c = cleanedStr.charAt(i);
     if (c == ' ') {
       if (i > 0 && cleanedStr.charAt(i - 1) == '-') {
         cleanedStr.deleteCharAt(i--);
       } else {
         c = '-';
         cleanedStr.setCharAt(i, c);
       }
       continue;
     }
     if (i > 0 && !(Character.isLetterOrDigit(c) || c == '-')) {
       cleanedStr.deleteCharAt(i--);
       continue;
     }
     if (i > 0 && c == '-' && cleanedStr.charAt(i - 1) == '-') cleanedStr.deleteCharAt(i--);
   }
   return cleanedStr.toString().toLowerCase();
 }
コード例 #27
0
ファイル: BibtexParser.java プロジェクト: abcdefghiklk/fixit
  /**
   * This method is used to parse string labels, field names, entry type and numbers outside
   * brackets.
   */
  private String parseTextToken() throws IOException {
    StringBuffer token = new StringBuffer(20);

    while (true) {
      int c = read();
      // Util.pr(".. "+c);
      if (c == -1) {
        _eof = true;

        return token.toString();
      }

      if (Character.isLetterOrDigit((char) c)
          || (c == ':')
          || (c == '-')
          || (c == '_')
          || (c == '*')
          || (c == '+')
          || (c == '.')
          || (c == '/')
          || (c == '\'')) {
        token.append((char) c);
      } else {
        unread(c);
        // Util.pr("Pasted text token: "+token.toString());
        return token.toString();
      }
    }
  }
コード例 #28
0
ファイル: WordIterator.java プロジェクト: BvbKoala/SourceCode
 private boolean isOnLetterOrDigit(int shiftedOffset) {
   if (shiftedOffset >= 0 && shiftedOffset < mString.length()) {
     final int codePoint = mString.codePointAt(shiftedOffset);
     if (Character.isLetterOrDigit(codePoint)) return true;
   }
   return false;
 }
コード例 #29
0
  protected boolean processKeyBinding(
      javax.swing.KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed) {
    // live search in current parent node
    if ((Character.isLetterOrDigit(e.getKeyChar())) && ks.isOnKeyRelease()) {
      char keyChar = e.getKeyChar();

      // search term
      String search = ("" + keyChar).toLowerCase();

      // try to find node with matching searchterm plus the search before
      int nextIndexMatching = getNextIndexMatching(cachedSearchKey + search);

      // if we did not find anything, try to find search term only: restart!
      if (nextIndexMatching < 0) {
        nextIndexMatching = getNextIndexMatching(search);
        cachedSearchKey = "";
      }
      // if we found a node, select it, make it visible and return true
      if (nextIndexMatching >= 0) {

        // store found treepath
        cachedSearchKey = cachedSearchKey + search;
        setSelectedIndex(nextIndexMatching);
        return true;
      }
      cachedSearchKey = "";
      return true;
    }
    return super.processKeyBinding(ks, e, condition, pressed);
  }
コード例 #30
0
ファイル: StringHelper.java プロジェクト: maduhu/cyclos-3
 /** Removes the given mask from the given value */
 public static String applyMask(final String mask, final String value) {
   if (StringUtils.isEmpty(mask) || value == null) {
     return value;
   }
   final StringBuilder sb = new StringBuilder();
   boolean nextIsLiteral = false;
   int pos = 0;
   for (int i = 0; i < mask.length(); i++) {
     final char c = mask.charAt(i);
     if (c == '\\') {
       nextIsLiteral = true;
     } else if (!nextIsLiteral && MASK_VARIABLES.indexOf(c) >= 0) {
       try {
         sb.append(value.charAt(pos++));
       } catch (final StringIndexOutOfBoundsException e) {
         continue;
       }
     } else {
       nextIsLiteral = false;
       sb.append(c);
       if (Character.isLetterOrDigit(c)) {
         pos++;
       }
     }
   }
   return sb.toString();
 }