Example usage for java.lang Character isWhitespace

List of usage examples for java.lang Character isWhitespace

Introduction

In this page you can find the example usage for java.lang Character isWhitespace.

Prototype

public static boolean isWhitespace(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is white space according to Java.

Usage

From source file:com.microsoft.tfs.util.datetime.LenientDateTimeParser.java

/**
 * Looks for common time zone strings at the end of the given dateTimeString
 * that {@link SimpleDateFormat} can't parse and converts them to equivalent
 * ones it can. For example, "Z" is turned into "UTC".
 *
 * @param dateTimeString/*from w ww  .  j a  va 2  s . co  m*/
 *        the date time string to parse. If null, null is returned.
 * @return the given dateTimeString with time zones converted to ones
 *         {@link SimpleDateFormat} can parse. Null if the given string was
 *         null.
 */
protected String convertUnsupportedTimeZones(final String dateTimeString) {
    if (dateTimeString == null) {
        return null;
    }

    /*
     * Convert additional UTC zone strings (like "Z" and "z") to "UTC". We
     * consider the dateTimeString to contain a matching zone string if it
     * ends with it, and the character before it is whitespace or numeric.
     * This lets a date time string like "2007-05-02T22:04:12Foobaz" pass
     * unaltered, because "Foobaz" refers to a (hypothetical) time zone name
     * which SimpleDateFormat could parse.
     */
    for (int i = 0; i < additionalUTCTimeZoneStrings.length; i++) {
        final String zoneString = additionalUTCTimeZoneStrings[i];

        if (dateTimeString.endsWith(zoneString)) {
            final int zoneIndex = dateTimeString.lastIndexOf(zoneString);

            // Make sure there's at least one character before the index.
            if (zoneIndex < 1) {
                continue;
            }

            final char previousChracter = dateTimeString.charAt(zoneIndex - 1);

            if (Character.isDigit(previousChracter) || Character.isWhitespace(previousChracter)) {
                // It's a match, replace the string anchored at the end with
                // UTC.
                return dateTimeString.replaceAll(zoneString + "$", "UTC"); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
    }

    return dateTimeString;
}

From source file:interactivespaces.util.process.BaseNativeApplicationRunner.java

/**
 * Extract environment variables.//  www. java  2 s  .  c om
 *
 * @param variables
 *          the string containing the environment variables
 */
private void extractEnvironment(String variables) {
    if (variables == null) {
        return;
    }

    // Now collect the individual arguments. The escape character will always
    // pass through the following character as part of the current token.
    String variableName = null;
    StringBuilder component = new StringBuilder();
    for (int i = 0; i <= variables.length(); i++) {
        // Force a space on the end to keep the end of a term processing from being duplicated.
        char ch = (i == variables.length()) ? ' ' : variables.charAt(i);
        if (Character.isWhitespace(ch)) {
            if (component.length() != 0) {
                if (variableName != null) {
                    environment.put(variableName, component.toString());
                    variableName = null;
                } else {
                    // No variable name so must have a variable name and a null value.
                    environment.put(component.toString(), null);
                }
                component.setLength(0);
            }
        } else if (ch == ESCAPE_CHARACTER) {
            i++;
            if (i < variables.length()) {
                component.append(variables.charAt(i));
            }
        } else if (ch == EQUALS_CHARACTER && variableName == null) {
            variableName = component.toString();
            component.setLength(0);
        } else {
            component.append(ch);
        }
    }
}

From source file:egovframework.asadal.asapro.com.cmm.util.AsaproEgovStringUtil.java

License:asdf

/**
 * <p>? String? ? ? ?? ? ?(stripChars) ? .</p>
 *
 * <pre>/*w  ww  .  j  a va  2  s.  c  o  m*/
 * StringUtil.stripStart(null, *)          = null
 * StringUtil.stripStart("", *)            = ""
 * StringUtil.stripStart("abc", "")        = "abc"
 * StringUtil.stripStart("abc", null)      = "abc"
 * StringUtil.stripStart("  abc", null)    = "abc"
 * StringUtil.stripStart("abc  ", null)    = "abc  "
 * StringUtil.stripStart(" abc ", null)    = "abc "
 * StringUtil.stripStart("yxabc  ", "xyz") = "abc  "
 * </pre>
 *
 * @param str ? ? ?  ?
 * @param stripChars ? ?
 * @return ? ? ? ?, null? ? <code>null</code> 
 */
public static String stripStart(String str, String stripChars) {
    int strLen;
    if (str == null || str.length() == 0) {
        return str;
    }
    strLen = str.length();
    int start = 0;
    if (stripChars == null) {
        while (start != strLen && Character.isWhitespace(str.charAt(start))) {
            start++;
        }
    } else if (stripChars.length() == 0) {
        return str;
    } else {
        while (start != strLen && stripChars.indexOf(str.charAt(start)) != -1) {
            start++;
        }
    }

    return str.substring(start);
}

From source file:com.silverwrist.venice.std.TrackbackManager.java

/**
 * Extracts an attribute value from the start of the string.  The attribute value may be enclosed
 * in quotes, or may simply be a series of nonblank characters delimited by blanks.
 *
 * @param s The string to extract the attribute value from.
 * @return The attribute value extracted.
 *//*from w ww .ja va 2  s. co  m*/
private static final String extractAttribute(String s) {
    char[] a = s.toCharArray();
    int i = 0;
    while ((i < a.length) && Character.isWhitespace(a[i]))
        i++;
    if (i == a.length)
        return "";
    int st = i;
    if ((a[st] == '\'') || (a[st] == '\"')) { // find quoted string boundaries
        i++;
        while ((i < a.length) && (a[i] != a[st]))
            i++;
        if (i == a.length)
            return "";
        st++;

    } // end if
    else { // skip over non-whitespace
        while ((i < a.length) && !(Character.isWhitespace(a[i])))
            i++;
        // if i==a.length, just take the "rest"

    } // end else

    if (i == a.length)
        return s.substring(st);
    else
        return s.substring(st, i);

}

From source file:haven.Utils.java

public static String[] splitwords(String text) {
    ArrayList<String> words = new ArrayList<String>();
    StringBuilder buf = new StringBuilder();
    String st = "ws";
    int i = 0;// www  .ja va2  s. c  o m
    while (i < text.length()) {
        char c = text.charAt(i);
        if (st == "ws") {
            if (!Character.isWhitespace(c))
                st = "word";
            else
                i++;
        } else if (st == "word") {
            if (c == '"') {
                st = "quote";
                i++;
            } else if (c == '\\') {
                st = "squote";
                i++;
            } else if (Character.isWhitespace(c)) {
                words.add(buf.toString());
                buf = new StringBuilder();
                st = "ws";
            } else {
                buf.append(c);
                i++;
            }
        } else if (st == "quote") {
            if (c == '"') {
                st = "word";
                i++;
            } else if (c == '\\') {
                st = "sqquote";
                i++;
            } else {
                buf.append(c);
                i++;
            }
        } else if (st == "squote") {
            buf.append(c);
            i++;
            st = "word";
        } else if (st == "sqquote") {
            buf.append(c);
            i++;
            st = "quote";
        }
    }
    if (st == "word")
        words.add(buf.toString());
    if ((st != "ws") && (st != "word"))
        return (null);
    return (words.toArray(new String[0]));
}

From source file:com.puppycrawl.tools.checkstyle.utils.CommonUtil.java

/**
 * Checks if the value arg is blank by either being null,
 * empty, or contains only whitespace characters.
 * @param value A string to check.// www  . j  a  v a  2s.  c  o m
 * @return true if the arg is blank.
 */
public static boolean isBlank(String value) {
    boolean result = true;
    if (value != null && !value.isEmpty()) {
        for (int i = 0; i < value.length(); i++) {
            if (!Character.isWhitespace(value.charAt(i))) {
                result = false;
                break;
            }
        }
    }
    return result;
}

From source file:com.liferay.ide.server.core.portal.PortalServerBehavior.java

private String _mergeArguments(String orgArgsString, String[] newArgs, String[] excludeArgs) {
    String retval = null;/*from w w  w.  j  av a  2  s.c  o m*/

    if (ListUtil.isEmpty(newArgs) && ListUtil.isEmpty(excludeArgs)) {
        retval = orgArgsString;
    } else {
        retval = orgArgsString == null ? "" : orgArgsString;

        String xbootClasspath = "";

        // replace and null out all newArgs that already exist

        int size = newArgs.length;

        for (int i = 0; i < size; i++) {
            if (newArgs[i].startsWith("-Xbootclasspath")) {
                xbootClasspath = xbootClasspath + newArgs[i] + " ";

                newArgs[i] = null;

                continue;
            }

            int ind = newArgs[i].indexOf(" ");
            int ind2 = newArgs[i].indexOf("=");

            if ((ind >= 0) && ((ind2 == -1) || (ind < ind2))) {

                // -a bc style

                int index = retval.indexOf(newArgs[i].substring(0, ind + 1));

                if ((index == 0) || ((index > 0) && Character.isWhitespace(retval.charAt(index - 1)))) {
                    newArgs[i] = null;
                }
            } else if (ind2 >= 0) {

                // a =b style

                int index = retval.indexOf(newArgs[i].substring(0, ind2 + 1));

                if ((index == 0) || ((index > 0) && Character.isWhitespace(retval.charAt(index - 1)))) {
                    newArgs[i] = null;
                }
            } else {

                // abc style

                int index = retval.indexOf(newArgs[i]);

                if ((index == 0) || ((index > 0) && Character.isWhitespace(retval.charAt(index - 1)))) {
                    newArgs[i] = null;
                }
            }
        }

        // remove excluded arguments

        if (ListUtil.isNotEmpty(excludeArgs)) {
            for (int i = 0; i < excludeArgs.length; i++) {
                int ind = excludeArgs[i].indexOf(" ");
                int ind2 = excludeArgs[i].indexOf("=");

                if ((ind >= 0) && ((ind2 == -1) || (ind < ind2))) {

                    // -a bc style

                    int index = retval.indexOf(excludeArgs[i].substring(0, ind + 1));

                    if ((index == 0) || ((index > 0) && Character.isWhitespace(retval.charAt(index - 1)))) {

                        // remove

                        String s = retval.substring(0, index);
                        int index2 = _getNextToken(retval, index + ind + 1);

                        if (index2 >= 0) {

                            // If remainder will become the first argument, remove leading blanks

                            while ((index2 < retval.length()) && Character.isWhitespace(retval.charAt(index2)))
                                index2 += 1;
                            retval = s + retval.substring(index2);
                        } else
                            retval = s;
                    }
                } else if (ind2 >= 0) {

                    // a =b style

                    int index = retval.indexOf(excludeArgs[i].substring(0, ind2 + 1));

                    if ((index == 0) || ((index > 0) && Character.isWhitespace(retval.charAt(index - 1)))) {

                        // remove

                        String s = retval.substring(0, index);
                        int index2 = _getNextToken(retval, index);

                        if (index2 >= 0) {

                            // If remainder will become the first argument, remove leading blanks

                            while ((index2 < retval.length()) && Character.isWhitespace(retval.charAt(index2)))
                                index2 += 1;
                            retval = s + retval.substring(index2);
                        } else
                            retval = s;
                    }
                } else {

                    // abc style

                    int index = retval.indexOf(excludeArgs[i]);

                    if ((index == 0) || ((index > 0) && Character.isWhitespace(retval.charAt(index - 1)))) {

                        // remove

                        String s = retval.substring(0, index);
                        int index2 = _getNextToken(retval, index);

                        if (index2 >= 0) {

                            // Remove leading blanks

                            while ((index2 < retval.length()) && Character.isWhitespace(retval.charAt(index2)))
                                index2 += 1;
                            retval = s + retval.substring(index2);
                        } else {
                            retval = s;
                        }
                    }
                }
            }
        }

        // add remaining vmargs to the end

        for (int i = 0; i < size; i++) {
            if (newArgs[i] != null) {
                if ((retval.length() > 0) && !retval.endsWith(" ")) {
                    retval += " ";
                }

                retval += newArgs[i];
            }
        }

        if (!CoreUtil.isNullOrEmpty(xbootClasspath)) {

            // delete xbootclasspath

            int xbootIndex = retval.lastIndexOf("-Xbootclasspath");

            while (xbootIndex != -1) {
                String head = retval.substring(0, xbootIndex);

                int tailIndex = _getNextToken(retval, xbootIndex);

                String tail = retval.substring(tailIndex == retval.length() ? retval.length() : tailIndex + 1);

                retval = head + tail;

                xbootIndex = retval.lastIndexOf("-Xbootclasspath");
            }

            retval = retval + " " + xbootClasspath;
        }
    }

    return retval;
}

From source file:net.sf.jasperreports.functions.standard.TextFunctions.java

private static boolean isDelimiter(char c) {
    return Character.isWhitespace(c) || Character.isSpaceChar(c);
}

From source file:com.krawler.portal.util.StringUtil.java

public static String shorten(String s, int length, String suffix) {
    if ((s == null) || (suffix == null)) {
        return null;
    }//w  w  w .j a va  2s .  co  m

    if (s.length() > length) {
        for (int j = length; j >= 0; j--) {
            if (Character.isWhitespace(s.charAt(j))) {
                length = j;

                break;
            }
        }

        StringBuilder sb = new StringBuilder();

        sb.append(s.substring(0, length));
        sb.append(suffix);

        s = sb.toString();
    }

    return s;
}

From source file:com.net.cookie.HttpCookie.java

private boolean isValidName(String n) {
    // name cannot be empty or begin with '$' or equals the reserved
    // attributes (case-insensitive)
    boolean isValid = !(n.length() == 0 || n.startsWith("$") || RESERVED_NAMES.contains(n.toLowerCase()));
    if (isValid) {
        for (int i = 0; i < n.length(); i++) {
            char nameChar = n.charAt(i);
            // name must be ASCII characters and cannot contain ';', ',' and
            // whitespace
            if (nameChar < 0 || nameChar >= 127 || nameChar == ';' || nameChar == ','
                    || (Character.isWhitespace(nameChar) && nameChar != ' ')) {
                isValid = false;/*from  ww w.j a  v  a 2s. co  m*/
                break;
            }
        }
    }
    return isValid;
}