Example usage for java.lang Character isSpaceChar

List of usage examples for java.lang Character isSpaceChar

Introduction

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

Prototype

public static boolean isSpaceChar(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a Unicode space character.

Usage

From source file:com.miz.functions.MizLib.java

/**
 * Adds spaces between capital characters.
 * @param s (input String)//from  w  w  w .  j a  v a 2 s  .c o  m
 * @return Input string with spaces between capital characters.
 */
public static String addSpaceByCapital(String s) {
    if (TextUtils.isEmpty(s))
        return "";

    StringBuilder result = new StringBuilder();
    char[] chars = s.toCharArray();
    for (int i = 0; i < chars.length; i++)
        if (chars.length > (i + 1))
            if (Character.isUpperCase(chars[i])
                    && (Character.isLowerCase(chars[i + 1]) && !Character.isSpaceChar(chars[i + 1])))
                result.append(" ").append(chars[i]);
            else
                result.append(chars[i]);
        else
            result.append(chars[i]);
    return result.toString().trim();
}

From source file:org.commonjava.sshwrap.config.DefaultSSHConfiguration.java

private static String nows(final String value) {
    final StringBuilder b = new StringBuilder();
    for (int i = 0; i < value.length(); i++) {
        if (!Character.isSpaceChar(value.charAt(i))) {
            b.append(value.charAt(i));//from   www. j ava2  s  .  c o m
        }
    }
    return b.toString();
}

From source file:com.avapira.bobroreader.hanabira.HanabiraParser.java

private void formatWordStrike() {
    int removedCharactersDelta = 0;
    Pattern pattern = Pattern.compile("(\\^W)+");
    Matcher matcher = pattern.matcher(builder);
    while (matcher.find()) {
        final int start = matcher.start() - removedCharactersDelta;
        final int end = matcher.end() - removedCharactersDelta;
        CodeBlockSpan[] spans = builder.getSpans(start, start, CodeBlockSpan.class);
        if (spans != null && spans.length != 0) {
            continue;
        }/*from   ww  w.  j a  v a 2 s  . co  m*/

        int wordsAmount = matcher.group().length() / 2;
        char[] chars = new char[builder.length()];
        builder.getChars(0, builder.length(), chars, 0);
        int runner = start;
        try {
            while (wordsAmount > 0) {
                if (Character.isSpaceChar(chars[runner--])) {
                    wordsAmount--;
                }
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            runner = 0;
        }
        builder.setSpan(new StrikethroughSpan(), runner, start, 0);
        builder.delete(start, end);
        removedCharactersDelta = end - start;
    }
}

From source file:org.languagetool.dev.wikipedia.TextConverter.java

private void write(String s) {
    if (s.isEmpty())
        return;/*from   w w  w. ja va  2 s  .  c o  m*/

    if (Character.isSpaceChar(s.charAt(0)))
        wantSpace();

    String[] words = ws.split(s);
    for (int i = 0; i < words.length;) {
        writeWord(words[i]);
        if (++i < words.length)
            wantSpace();
    }

    if (Character.isSpaceChar(s.charAt(s.length() - 1)))
        wantSpace();
}

From source file:org.realityforge.proxy_servlet.AbstractProxyServlet.java

/**
 * Encodes characters in the query or fragment part of the URI.
 * <p/>// ww  w .  j a  va  2 s  . c  o m
 * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec.  HttpClient
 * insists that the outgoing proxied request has a valid URI because it uses Java's {@link java.net.URI}.
 * To be more forgiving, we must escape the problematic characters.  See the URI class for the
 * spec.
 *
 * @param in example: name=value&foo=bar#fragment
 */
private static CharSequence encodeUriQuery(final CharSequence in) {
    //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things.
    StringBuilder sb = null;
    Formatter formatter = null;
    for (int i = 0; i < in.length(); i++) {
        char c = in.charAt(i);
        boolean escape = true;
        if (c < MAX_ASCII_VALUE) {
            if (ASCII_QUERY_CHARS.get((int) c)) {
                escape = false;
            }
        } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {
            //not-ascii
            escape = false;
        }
        if (!escape) {
            if (null != sb) {
                sb.append(c);
            }
        } else {
            //escape
            if (null == sb) {
                final int formatLength = 5 * 3;
                sb = new StringBuilder(in.length() + formatLength);
                sb.append(in, 0, i);
                formatter = new Formatter(sb);
            }
            //leading %, 0 padded, width 2, capital hex
            formatter.format("%%%02X", (int) c);
        }
    }
    return sb != null ? sb : in;
}

From source file:org.mule.providers.http.HttpMessageReceiver.java

private void readHeaders(RequestInputStream is, Properties p) throws IOException {
    String currentKey = null;//from w  ww. j av  a2s.c  o  m
    while (true) {
        String line = is.readline();
        if ((line == null) || (line.length() == 0)) {
            break;
        }

        if (!Character.isSpaceChar(line.charAt(0))) {
            int index = line.indexOf(':');
            if (index >= 0) {
                currentKey = line.substring(0, index).trim();
                if (currentKey.startsWith("X-" + MuleProperties.PROPERTY_PREFIX)) {
                    currentKey = currentKey.substring(2);
                } else {
                    // normalize incoming header if necessary
                    String normalizedKey = (String) HttpConstants.ALL_HEADER_NAMES.get(currentKey);
                    if (normalizedKey != null) {
                        currentKey = normalizedKey;
                    }
                }
                String value = line.substring(index + 1).trim();
                p.setProperty(currentKey, value);
            }
        } else if (currentKey != null) {
            String value = p.getProperty(currentKey);
            p.setProperty(currentKey, value + "\r\n\t" + line.trim());
        }
    }

}

From source file:org.ocpsoft.rewrite.servlet.config.proxy.ProxyServlet.java

/**
 * Encodes characters in the query or fragment part of the URI.
 * /*from   w  ww  . ja  v a2s. c om*/
 * <p>
 * Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient insists that the
 * outgoing proxied request has a valid URI because it uses Java's {@link URI}. To be more forgiving, we must escape
 * the problematic characters. See the URI class for the spec.
 * 
 * @param in example: name=value&foo=bar#fragment
 */
protected static CharSequence encodeUriQuery(CharSequence in) {
    /*
     * Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. TODO:
     * replace/compare to with Rewrite Encoding
     */
    StringBuilder outBuf = null;
    Formatter formatter = null;
    for (int i = 0; i < in.length(); i++) {
        char c = in.charAt(i);
        boolean escape = true;
        if (c < 128) {
            if (asciiQueryChars.get(c)) {
                escape = false;
            }
        } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {
            /*
             * not-ascii
             */
            escape = false;
        }
        if (!escape) {
            if (outBuf != null)
                outBuf.append(c);
        } else {
            /*
             * escape
             */
            if (outBuf == null) {
                outBuf = new StringBuilder(in.length() + 5 * 3);
                outBuf.append(in, 0, i);
                formatter = new Formatter(outBuf);
            }
            /*
             * leading %, 0 padded, width 2, capital hex
             */
            formatter.format("%%%02X", (int) c);// TODO
        }
    }
    return outBuf != null ? outBuf : in;
}

From source file:uk.ac.ebi.phenotype.web.proxy.ExternalUrlConfiguratbleProxyServlet.java

/**
 * <p>/* ww  w  .ja va 2s. co m*/
 * Encodes characters in the query or fragment part of the URI.
 * 
 * <p>
 * Unfortunately, an incoming URI sometimes has characters disallowed by the
 * spec. HttpClient insists that the outgoing proxied request has a valid
 * URI because it uses Java's {@link URI}. To be more forgiving, we must
 * escape the problematic characters. See the URI class for the spec.
 * 
 * @param in
 *            example: name=value&foo=bar#fragment
 */
static CharSequence encodeUriQuery(CharSequence in) {
    // Note that I can't simply use URI.java to encode because it will
    // escape pre-existing escaped things.
    StringBuilder outBuf = null;
    Formatter formatter = null;
    for (int i = 0; i < in.length(); i++) {
        char c = in.charAt(i);
        boolean escape = true;
        if (c < 128) {
            if (asciiQueryChars.get((int) c)) {
                escape = false;
            }
        } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {// not-ascii
            escape = false;
        }
        if (!escape) {
            if (outBuf != null)
                outBuf.append(c);
        } else {
            // escape
            if (outBuf == null) {
                outBuf = new StringBuilder(in.length() + 5 * 3);
                outBuf.append(in, 0, i);
                formatter = new Formatter(outBuf);
            }
            // leading %, 0 padded, width 2, capital hex
            formatter.format("%%%02X", (int) c);// TODO
        }
    }
    return outBuf != null ? outBuf : in;
}

From source file:com.coinblesk.client.KeyboardFragment.java

private static String trimLeadingZeros(String source) {
    for (int i = 0; i < source.length(); ++i) {
        char c = source.charAt(i);
        if (c != '0' && !Character.isSpaceChar(c))
            return source.substring(i);
    }/*from   ww w. j a  v a 2s .  c o  m*/
    return source;
}