spyglass/src/main/java/com/linkedin/android/spyglass/tokenization/impl/WordTokenizer.java
public boolean isValidMention(final @NonNull Spanned text, final int start, final int end) {
        // Get the token
        CharSequence token = text.subSequence(start, end);

        // Null or empty string is not a valid mention
        if (TextUtils.isEmpty(token)) {
            return false;
        }

        // Handle explicit mentions first, then implicit mentions
        final int threshold = mConfig.THRESHOLD;
        boolean multipleWords = containsWordBreakingChar(token);
        boolean containsExplicitChar = containsExplicitChar(token);

        if (!multipleWords && containsExplicitChar) {

            // If it is one word and has an explicit char, the explicit char must be the first char
            if (!isExplicitChar(token.charAt(0))) {
                return false;
            }

            // Ensure that the character before the explicit character is a word-breaking character
            // Note: Checks the explicit character closest in front of the cursor
            if (!hasWordBreakingCharBeforeExplicitChar(text, end)) {
                return false;
            }

            // Return true if string is just an explicit character
            if (token.length() == 1) {
                return true;
            }

            // If input has length greater than one, the second character must be a letter or digit
            // Return true if and only if second character is a letter or digit, i.e. "@d"
            return Character.isLetterOrDigit(token.charAt(1));

        } else if (token.length() >= threshold) {

            // Change behavior depending on if keywords is one or more words
            if (!multipleWords) {
                // One word, no explicit characters
                // input is only one word, i.e. "u41"
                return onlyLettersOrDigits(token, threshold, 0);
            } else if (containsExplicitChar) {
                // Multiple words, has explicit character
                // Must have a space, the explicit character, then a letter or digit
                return hasWordBreakingCharBeforeExplicitChar(text, end)
                        && isExplicitChar(token.charAt(0))
                        && Character.isLetterOrDigit(token.charAt(1));
            } else {
                // Multiple words, no explicit character
                // Either the first or last couple of characters must be letters/digits
                boolean firstCharactersValid = onlyLettersOrDigits(token, threshold, 0);
                boolean lastCharactersValid = onlyLettersOrDigits(token, threshold, token.length() - threshold);
                return firstCharactersValid || lastCharactersValid;
            }
        }

        return false;
    }
public boolean isValidMention(final @NonNull Spanned text, final int start, final int end) {
        // Get the token
        CharSequence token = text.subSequence(start, end);

        // Null or empty string is not a valid mention
        if (TextUtils.isEmpty(token)) {
            return false;
        }

        // Handle explicit mentions first, then implicit mentions
        final int threshold = mConfig.THRESHOLD;
        boolean multipleWords = containsWordBreakingChar(token);
        boolean containsExplicitChar = containsExplicitChar(token);

        if (!multipleWords && containsExplicitChar) {

            // If it is one word and has an explicit char, the explicit char must be the first char
            if (!isExplicitChar(token.charAt(0))) {
                return false;
            }

            // Ensure that the character before the explicit character is a word-breaking character
            // Note: Checks the explicit character closest in front of the cursor
            if (!hasWordBreakingCharBeforeExplicitChar(text, end)) {
                return false;
            }

            // Return true if string is just an explicit character
            if (token.length() == 1) {
                return true;
            }

            // If input has length greater than one, the second character must be a letter or digit
            // Return true if and only if second character is a letter or digit, i.e. "@d"
            return Character.isLetterOrDigit(token.charAt(1));

        } else if (token.length() >= threshold) {

            // Change behavior depending on if keywords is one or more words
            if (!multipleWords) {
                // One word, no explicit characters
                // input is only one word, i.e. "u41"
                return onlyLettersOrDigits(token, threshold, 0);
            } else if (containsExplicitChar) {
                // Multiple words, has explicit character
                // Must have a space, the explicit character, then a letter or digit
                return hasWordBreakingCharBeforeExplicitChar(text, end)
                        && isExplicitChar(token.charAt(0))
                        && Character.isLetterOrDigit(token.charAt(1));
            } else {
                // Multiple words, no explicit character
                // Either the first or last couple of characters must be letters/digits
                boolean firstCharactersValid = onlyLettersOrDigits(token, threshold, 0);
                boolean lastCharactersValid = onlyLettersOrDigits(token, threshold, token.length() - threshold);
                return firstCharactersValid || lastCharactersValid;
            }
        }

        return false;
    }
public boolean isValidMention ( final @ NonNull Spanned text , final int start , final int end ) { // Get the token CharSequence token = text . subSequence ( start , end ) ; // Null or empty string is not a valid mention if ( TextUtils . isEmpty ( token ) ) { return false ; } // Handle explicit mentions first, then implicit mentions final int threshold = mConfig . THRESHOLD ; boolean multipleWords = containsWordBreakingChar ( token ) ; boolean containsExplicitChar = containsExplicitChar ( token ) ; if ( ! multipleWords && containsExplicitChar ) { // If it is one word and has an explicit char, the explicit char must be the first char if ( ! isExplicitChar ( token . charAt ( 0 ) ) ) { return false ; } // Ensure that the character before the explicit character is a word-breaking character // Note: Checks the explicit character closest in front of the cursor if ( ! hasWordBreakingCharBeforeExplicitChar ( text , end ) ) { return false ; } // Return true if string is just an explicit character if ( token . length ( ) == 1 ) { return true ; } // If input has length greater than one, the second character must be a letter or digit // Return true if and only if second character is a letter or digit, i.e. "@d" return Character . isLetterOrDigit ( token . charAt ( 1 ) ) ; } else if ( token . length ( ) >= threshold ) { // Change behavior depending on if keywords is one or more words if ( ! multipleWords ) { // One word, no explicit characters // input is only one word, i.e. "u41" return onlyLettersOrDigits ( token , threshold , 0 ) ; } else if ( containsExplicitChar ) { // Multiple words, has explicit character // Must have a space, the explicit character, then a letter or digit return hasWordBreakingCharBeforeExplicitChar ( text , end ) && isExplicitChar ( token . charAt ( 0 ) ) && Character . isLetterOrDigit ( token . charAt ( 1 ) ) ; } else { // Multiple words, no explicit character // Either the first or last couple of characters must be letters/digits boolean firstCharactersValid = onlyLettersOrDigits ( token , threshold , 0 ) ; boolean lastCharactersValid = onlyLettersOrDigits ( token , threshold , token . length ( ) - threshold ) ; return firstCharactersValid || lastCharactersValid ; } } return false ; }
{@inheritDoc}
{