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.netspective.sparx.util.xml.XmlSource.java

/**
 * Return the given text unindented by whatever the first line is indented by
 * @param text The original text//from  w w  w.j  a  v a  2 s. c o m
 * @return Unindented text or original text if not indented
 */
public static String getUnindentedText(String text) {
    /*
     * if the entire SQL 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 + "/\n/g", text).trim();
    else
        return text;
}

From source file:com.microsoft.rest.interceptors.LoggingInterceptor.java

private static boolean isPlaintext(Buffer buffer) throws EOFException {
    try {//from  w  w w. j a  v a 2  s. com
        Buffer prefix = new Buffer();
        long byteCount = buffer.size() < 64 ? buffer.size() : 64;
        buffer.copyTo(prefix, 0, byteCount);
        for (int i = 0; i < 16; i++) {
            if (prefix.exhausted()) {
                break;
            }
            int codePoint = prefix.readUtf8CodePoint();
            if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) {
                return false;
            }
        }
        return true;
    } catch (EOFException e) {
        return false;
    }
}

From source file:com.stratio.ingestion.serializer.elasticsearch.ElasticSearchSerializerWithMappingTest.java

private String trimAllWhitespace(String str) {
    if (!hasLength(str)) {
        return str;
    }/*w w  w  . j av a  2 s  .co  m*/
    StringBuilder sb = new StringBuilder(str);
    int index = 0;
    while (sb.length() > index) {
        if (Character.isWhitespace(sb.charAt(index))) {
            sb.deleteCharAt(index);
        } else {
            index++;
        }
    }
    return sb.toString();
}

From source file:com.github.jknack.semver.SemverParser.java

private String ws() {
    return match(new Matcher() {
        @Override//from  ww  w. j  a  va2 s . c  o  m
        public boolean match(final char ch) {
            return Character.isWhitespace(ch);
        }
    });
}

From source file:MsgPrinter.java

/**
 * Returns the index of the last character of the next word, plus 1, or
 * IS_NEWLINE if a newline character is encountered before the next word,
 * or IS_EOS if the end of the string is ecnounterd before the next
 * word. The method first skips all whitespace characters at or after
 * 'from', except newlines. If a newline is found IS_NEWLINE is
 * returned. Then it skips all non-whitespace characters and returns the
 * position of the last non-whitespace character, plus 1. The returned
 * index may be greater than the last valid index in the tsring, but it is
 * always suitable to be used in the String.substring() method.
 *
 * <P>Non-whitespace characters are defined as in the
 * Character.isWhitespace method (that method is used).
 *
 * @param str The string to parse/*from w w  w. ja  va 2s . c  o m*/
 *
 * @param from The index of the first position to search from
 *
 * @return The index of the last character in the next word, plus 1,
 * IS_NEWLINE, or IS_EOS if there are no more words.
 *
 *
 * */
private int nextLineEnd(String str, int from) {
    final int len = str.length();
    char c = '\0';
    // First skip all whitespace, except new line
    while (from < len && (c = str.charAt(from)) != '\n' && Character.isWhitespace(c)) {
        from++;
    }
    if (c == '\n') {
        return IS_NEWLINE;
    }
    if (from >= len) {
        return IS_EOS;
    }
    // Now skip word characters
    while (from < len && !Character.isWhitespace(str.charAt(from))) {
        from++;
    }
    return from;
}

From source file:htsjdk.samtools.reference.FastaReferenceWriter.java

private static void checkSequenceName(final String name) {
    ValidationUtils.nonEmpty(name, "Sequence name");

    for (int i = 0; i < name.length(); i++) {
        final char ch = name.charAt(i);
        if (Character.isWhitespace(ch)) {
            throw new IllegalArgumentException("the input name contains blank characters: '" + name + "'");
        } else if (Character.isISOControl(ch)) {
            throw new IllegalArgumentException("the input name contains control characters: '" + name + "'");
        }/*from www. j  a v  a  2s . c om*/
    }
}

From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java

private boolean atEndOfWord(JTextComponent textField) {
    int nextCharPosition = textField.getCaretPosition();

    // position not at the end of input
    if (nextCharPosition < textField.getText().length()) {
        char nextChar = textField.getText().charAt(nextCharPosition);
        if (!Character.isWhitespace(nextChar)) {
            return false;
        }//  w  w w  .jav a  2s .co  m
    }
    return true;
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java

static String removeWhiteSpaces(String string) {
    if (string == null) {
        return "";
    }//from w w  w.jav  a 2  s  .  c  o  m

    final int length = string.length();
    if (length < 1) {
        return string;
    }

    StringBuilder sb = new StringBuilder(length);
    for (int i = 0; i < length; i++) {
        final char c = string.charAt(i);
        if (!Character.isWhitespace(c)) {
            sb.append(c);
        }
    }

    return sb.toString();
}

From source file:net.sf.jabref.bst.BibtexCaseChanger.java

/**
 * Convert the given string according to the format character (title, lower,
 * up) and append the result to the stringBuffer, return the updated
 * position.//  ww  w .  j  a  va2 s. c o m
 *
 * @param c
 * @param start
 * @param s
 * @param sb
 * @param format
 * @return the new position
 */
private int convertAccented(char[] c, int start, String s, StringBuilder sb, FORMAT_MODE format) {
    int pos = start;
    pos += s.length();

    switch (format) {
    case TITLE_LOWERS:
    case ALL_LOWERS:
        if ("L O OE AE AA".contains(s)) {
            sb.append(s.toLowerCase());
        } else {
            sb.append(s);
        }
        break;
    case ALL_UPPERS:
        if ("l o oe ae aa".contains(s)) {
            sb.append(s.toUpperCase());
        } else if ("i j ss".contains(s)) {
            sb.deleteCharAt(sb.length() - 1); // Kill backslash
            sb.append(s.toUpperCase());
            while ((pos < c.length) && Character.isWhitespace(c[pos])) {
                pos++;
            }
        } else {
            sb.append(s);
        }
        break;
    default:
        LOGGER.info("convertAccented - Unknown format: " + format);
        break;
    }
    return pos;
}

From source file:importer.handler.post.stages.SAXSplitter.java

private boolean isWhitespace(String str) {
    boolean answer = true;
    for (int i = 0; i < str.length(); i++) {
        if (!Character.isWhitespace(str.charAt(i)))
            answer = false;/*  www.  ja  v  a  2 s . co  m*/
        else if (str.charAt(i) == '\n') {
            lineNo++;
            if (lineNo == 13153)
                System.out.println("13153");
        }
    }
    return answer;
}