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:egovframework.asadal.asapro.com.cmm.util.AsaproEgovStringUtil.java

License:asdf

/**
 * <p>? String? ? ? ?? ? ?(stripChars) ? .</p>
 *
 * <pre>/*from   w  ww  .j ava 2  s . c om*/
 * StringUtil.stripEnd(null, *)          = null
 * StringUtil.stripEnd("", *)            = ""
 * StringUtil.stripEnd("abc", "")        = "abc"
 * StringUtil.stripEnd("abc", null)      = "abc"
 * StringUtil.stripEnd("  abc", null)    = "  abc"
 * StringUtil.stripEnd("abc  ", null)    = "abc"
 * StringUtil.stripEnd(" abc ", null)    = " abc"
 * StringUtil.stripEnd("  abcyx", "xyz") = "  abc"
 * </pre>
 *
 * @param str ? ? ?  ?
 * @param stripChars ? ?
 * @return ? ? ? ?, null? ? <code>null</code> 
 */
public static String stripEnd(String str, String stripChars) {
    int end;
    if (str == null || str.length() == 0) {
        return str;
    }
    end = str.length();
    if (stripChars == null) {
        while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) {
            end--;
        }
    } else if (stripChars.length() == 0) {
        return str;
    } else {
        while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != -1) {
            end--;
        }
    }

    return str.substring(0, end);
}

From source file:com.mirth.connect.plugins.datatypes.delimited.DelimitedReader.java

/**
 * Removes trailing whitespace from a string and returns it.
 * /*from  ww  w . j  av  a2s  .  co m*/
 * @param s
 *            The input string.
 * @return If the input string has trailing whitespace, a new string with the whitespace
 *         removed, otherwise, return s.
 */
private String ltrim(String s) {

    if (s.length() == 0)
        return s;

    int i = s.length() - 1;
    while (i >= 0 && Character.isWhitespace(s.charAt(i))) {
        i--;
    }

    if (i == s.length() - 1)
        return s;
    else if (i == -1)
        return new String();
    else
        return s.substring(0, i + 1);
}

From source file:com.prodigy4440.view.MainJFrame.java

private static long wordCount(String line) {

    long numWords = 0;

    int index = 0;

    boolean prevWhiteSpace = true;

    while (index < line.length()) {

        char c = line.charAt(index++);

        boolean currWhiteSpace = Character.isWhitespace(c);

        if (prevWhiteSpace && !currWhiteSpace) {

            numWords++;/*  www  .  j a v  a  2 s  .com*/

        }

        prevWhiteSpace = currWhiteSpace;

    }

    return numWords;

}

From source file:de.homelab.madgaksha.lotsofbs.util.LocaleRootWordUtils.java

/**
 * Is the character a delimiter.//  w  w  w .ja v  a  2s . co  m
 *
 * @param ch
 *            the character to check
 * @param delimiters
 *            the delimiters
 * @return true if it is a delimiter
 */
private static boolean isDelimiter(final char ch, final char[] delimiters) {
    if (delimiters == null) {
        return Character.isWhitespace(ch);
    }
    for (final char delimiter : delimiters) {
        if (ch == delimiter) {
            return true;
        }
    }
    return false;
}

From source file:com.almarsoft.GroundhogReader.lib.MessageTextProcessor.java

public static Vector<HashMap<String, String>> saveUUEncodedAttachments(BufferedReader bodyTextReader,
        String group) throws IOException {

    Vector<HashMap<String, String>> bodyAttachments = new Vector<HashMap<String, String>>(1);
    String newBody = null;/*  w  w  w. ja  va2s  .  c o m*/
    Vector<HashMap<String, String>> attachDatas = null;

    StringBuilder newBodyBuilder = new StringBuilder();
    StringBuilder attachment = new StringBuilder();

    boolean inAttach = false;
    boolean firstOfTheEnd = false;

    String line, sline, filename = null;
    HashMap<String, String> attachData = null;

    attachDatas = new Vector<HashMap<String, String>>();

    while ((line = bodyTextReader.readLine()) != null) {

        // XXX: Probar a quitar esto (optimizacion)
        sline = line.trim();

        if (sline.equals("`")) {
            firstOfTheEnd = true;
            attachment.append(line + "\n");
        }

        else if (firstOfTheEnd && inAttach && sline.equals("end")) {

            attachment.append(line + "\n");
            if (attachDatas == null)
                attachDatas = new Vector<HashMap<String, String>>();

            try {
                attachData = FSUtils.saveUUencodedAttachment(attachment.toString(), filename, group);
                attachDatas.add(attachData);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (UsenetReaderException e) {
                e.printStackTrace();
            }
            attachment = null;
            inAttach = false;
            firstOfTheEnd = false;
        }

        else if (firstOfTheEnd && inAttach && !sline.equals("end")) {
            firstOfTheEnd = false; // False alarm?
        }

        // XXX: ESTO NO SOPORTA UUENCODED SIN PERMISOS!!!
        else if (sline.length() >= 11 && sline.substring(0, 6).equals("begin ")
                && Character.isDigit(sline.charAt(6)) && Character.isDigit(sline.charAt(7))
                && Character.isDigit(sline.charAt(8)) && Character.isWhitespace(sline.charAt(9))
                && !Character.isWhitespace(sline.charAt(10))) {

            filename = sline.substring(10);
            inAttach = true;
            attachment.append(line + "\n");
        }

        else if (inAttach) {
            attachment.append(line + "\n");
        }

        else {
            newBodyBuilder.append(line + "\n");
        }

    }
    newBody = newBodyBuilder.toString();

    // Add the new body as first element
    HashMap<String, String> bodyMap = new HashMap<String, String>(1);
    bodyMap.put("body", newBody);
    bodyAttachments.add(bodyMap);

    if (attachDatas != null) {
        for (HashMap<String, String> attData : attachDatas) {
            bodyAttachments.insertElementAt(attData, 1);
        }
    }

    return bodyAttachments;
}

From source file:it.geosdi.era.server.servlet.HTTPProxy.java

public static int escapeHtmlFull(int ch) {
    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9') {
        // safe/*from w w  w  . j  av  a 2 s .c  o m*/
        return ch;
    } else if (Character.isWhitespace(ch)) {
        if (ch != '\n' && ch != '\r' && ch != '\t')
            // safe
            return ch;
    } else if (Character.isDefined(ch)) {
        // safe
        return ch;
    } else if (Character.isISOControl(ch)) {
        // paranoid version:isISOControl which are not isWhitespace
        // removed !
        // do nothing do not include in output !
        return -1;
    } else if (Character.isHighSurrogate((char) ch)) {
        // do nothing do not include in output !
        return -1;
    } else if (Character.isLowSurrogate((char) ch)) {
        // wrong char[] sequence, //TODO: LOG !!!
        return -1;
    }

    return -1;
}

From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java

public boolean isBlank(CharSequence cs) {
    int strLen;//from  w  w w. j av  a2 s.c om
    if ((cs == null) || ((strLen = cs.length()) == 0))
        return true;
    for (int i = 0; i < strLen; i++) {
        if (!Character.isWhitespace(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.commons.lang3.StringUtils.java

/**
 * <p>Strips any of a set of characters from the start of a String.</p>
 *
 * <p>A {@code null} input String returns {@code null}.
 * An empty string ("") input returns the empty string.</p>
 *
 * <p>If the stripChars String is {@code null}, whitespace is
 * stripped as defined by {@link Character#isWhitespace(char)}.</p>
 *
 * <pre>/*from  w  w w .  ja v  a  2 s  . co  m*/
 * StringUtils.stripStart(null, *)          = null
 * StringUtils.stripStart("", *)            = ""
 * StringUtils.stripStart("abc", "")        = "abc"
 * StringUtils.stripStart("abc", null)      = "abc"
 * StringUtils.stripStart("  abc", null)    = "abc"
 * StringUtils.stripStart("abc  ", null)    = "abc  "
 * StringUtils.stripStart(" abc ", null)    = "abc "
 * StringUtils.stripStart("yxabc  ", "xyz") = "abc  "
 * </pre>
 *
 * @param str  the String to remove characters from, may be null
 * @param stripChars  the characters to remove, null treated as whitespace
 * @return the stripped String, {@code null} if null String input
 */
public static String stripStart(String str, String stripChars) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }
    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)) != INDEX_NOT_FOUND) {
            start++;
        }
    }
    return str.substring(start);
}

From source file:com.netspective.commons.text.TextUtils.java

/**
 * Return the given text unindented by whatever the first line is indented by
 *
 * @param text The original text//  w  w w.j a  va 2s  .  co m
 *
 * @return Unindented text or original text if not indented
 */
public String getUnindentedText(String text) {
    /*
     * if the string is indented, find out how far the first line is indented
     */
    StringBuffer replStr = new StringBuffer();
    for (int i = 0; i < text.length(); i++) {
        char ch = text.charAt(i);
        if (Character.isWhitespace(ch))
            replStr.append(ch);
        else
            break;
    }

    /*
     * If the first line is indented, unindent all the lines the distance of just the first line
     */
    Perl5Util perlUtil = new Perl5Util();

    if (replStr.length() > 0)
        return perlUtil.substitute("s/^" + replStr + "//gm", text).trim();
    else
        return text;
}

From source file:ch.randelshofer.cubetwister.HTMLExporter.java

/**
 * Converts a String, so that it only contains lower case ASCII characters.
 *//*from   www  .j  a  v  a  2s  .  co m*/
private String toID(String str) {
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < str.length(); i++) {
        char ch = Character.toLowerCase(str.charAt(i));
        if (Character.isJavaIdentifierPart(ch)) {
            buf.append(ch);
        } else if (Character.isWhitespace(ch)) {
            buf.append('_');
        }
    }
    return buf.toString();
}