Code example for Pattern

Methods: split

0
    // "abc|" -> null 
    // "abc |" -> null 
    // "abc. def|" -> null 
    public static CharSequence getPreviousWord(CharSequence prev, String sentenceSeperators) {
        if (prev == null) return null;
        String[] w = spaceRegex.split(prev);
 
        // If we can't find two words, or we found an empty word, return null. 
        if (w.length < 2 || w[w.length - 2].length() <= 0) return null;
 
        // If ends in a separator, return null 
        char lastChar = w[w.length - 2].charAt(w[w.length - 2].length() - 1);
        if (sentenceSeperators.contains(String.valueOf(lastChar))) return null;
 
        return w[w.length - 2];
    } 
 
    public static CharSequence getThisWord(InputConnection connection, String sentenceSeperators) {
        if (null == connection) return null;
        final CharSequence prev = connection.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
        return getThisWord(prev, sentenceSeperators);