Java String Starts Wtih startsWithPhraseSeparator(char[] token)

Here you can find the source of startsWithPhraseSeparator(char[] token)

Description

Check if token starts with a phrase separator

License

Open Source License

Parameter

Parameter Description
token a parameter

Declaration

public static boolean startsWithPhraseSeparator(char[] token) 

Method Source Code

//package com.java2s;
/**//from   w ww  .  ja v  a2 s .  c om
 *  ClusteringWiki - personalized and collaborative clustering of search results
 *  Copyright (C) 2010  Texas State University-San Marcos
 *  
 *  Contact: http://dmlab.cs.txstate.edu
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Check if token starts with a phrase separator
     * @param token
     * @return
     */
    public static boolean startsWithPhraseSeparator(char[] token) {
        return token.length > 0 && isPhraseSeparator(token[0]);
    }

    /**
     * Check if token starts with a phrase separator
     * @param token
     * @return
     */
    public static boolean startsWithPhraseSeparator(String token) {
        final int ln = token.length();
        return ln > 0 && isPhraseSeparator(token.charAt(0));
    }

    /**
     * Check if token is a phrase separator
     * @param token
     * @return
     */
    public static boolean isPhraseSeparator(char[] token) {
        return isPhraseSeparator(token, 0, token.length);
    }

    /**
     * Check if token is a phrase separator
     * @param token
     * @return
     */
    public static boolean isPhraseSeparator(String token) {
        return isPhraseSeparator(token.toCharArray(), 0, token.length());
    }

    /**
     * Check if token is a phrase separator
     * @param token
     * @param start
     * @param end
     * @return
     */
    public static boolean isPhraseSeparator(char[] token, int start, int end) {
        for (int i = start; i < end; i++)
            if (!isPhraseSeparator(token[i]))
                return false;
        return true;
    }

    /**
     * Check if chracter is a phrase separator
     * @param token
     * @return
     */
    public static boolean isPhraseSeparator(char token) {
        if (Character.isLetterOrDigit(token))
            return false;
        switch (token) {
        case '.':
        case '!':
        case '?':
        case ',':
        case '\'':
        case '"':
        case '(':
        case ')':
            //case '&': //causes break on html codes, should be handled separately
        case ':':
        case ';':
        case '[':
        case ']':
        case '{':
        case '}':
        case '|':
        case '\\':
        case '/':
            return true;
        default:
            //nothing
        }
        return false;
    }
}

Related

  1. startsWithOneOf(String source, boolean ignoreCase, String... values)
  2. startsWithOneOf(String str, String... strs)
  3. startsWithOneOf(String string, String... prefixes)
  4. startsWithOrMatches(String s1, String s2)
  5. startsWithPattern(String value, String matchingPatterns)
  6. startsWithPrefix(final String methodName, final String prefix, final int prefixLength)
  7. startsWithPrefix(String inputText, String[] prefixes)
  8. startsWithQuote(String str)
  9. startsWithSeparator(String str)