Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

In this page you can find the example usage for java.lang CharSequence length.

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:com.surveypanel.utils.PlaceHolderParser.java

private static int findPlaceholderEndIndex(CharSequence buf, int startIndex) {
    int index = startIndex + DEFAULT_PLACEHOLDER_PREFIX.length();
    int withinNestedPlaceholder = 0;
    while (index < buf.length()) {
        if (StringUtils.substringMatch(buf, index, DEFAULT_PLACEHOLDER_SUFFIX)) {
            if (withinNestedPlaceholder > 0) {
                withinNestedPlaceholder--;
                index = index + DEFAULT_PLACEHOLDER_SUFFIX.length();
            } else {
                return index;
            }// ww w .  jav  a  2s.  c  o  m
        } else if (StringUtils.substringMatch(buf, index, DEFAULT_PLACEHOLDER_PREFIX)) {
            withinNestedPlaceholder++;
            index = index + DEFAULT_PLACEHOLDER_PREFIX.length();
        } else {
            index++;
        }
    }
    return -1;
}

From source file:com.examples.with.different.packagename.StringUtils.java

/**
 * <p>Checks if CharSequence contains a search CharSequence irrespective of case,
 * handling {@code null}. Case-insensitivity is defined as by
 * {@link String#equalsIgnoreCase(String)}.
 *
 * <p>A {@code null} CharSequence will return {@code false}.</p>
 *
 * <pre>/*from w w  w .  j  av a 2 s. c  o m*/
 * StringUtils.contains(null, *) = false
 * StringUtils.contains(*, null) = false
 * StringUtils.contains("", "") = true
 * StringUtils.contains("abc", "") = true
 * StringUtils.contains("abc", "a") = true
 * StringUtils.contains("abc", "z") = false
 * StringUtils.contains("abc", "A") = true
 * StringUtils.contains("abc", "Z") = false
 * </pre>
 *
 * @param str  the CharSequence to check, may be null
 * @param searchStr  the CharSequence to find, may be null
 * @return true if the CharSequence contains the search CharSequence irrespective of
 * case or false if not or {@code null} string input
 * @since 3.0 Changed signature from containsIgnoreCase(String, String) to containsIgnoreCase(CharSequence, CharSequence)
 */
public static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr) {
    if (str == null || searchStr == null) {
        return false;
    }
    final int len = searchStr.length();
    final int max = str.length() - len;
    for (int i = 0; i <= max; i++) {
        if (regionMatches(str, true, i, searchStr, 0, len)) {
            return true;
        }
    }
    return false;
}

From source file:com.appglu.impl.util.StringUtils.java

public static boolean isNotEmpty(CharSequence str) {
    if (!hasLength(str)) {
        return false;
    }/*from w w w  .j  a v  a 2  s  .  co  m*/
    int strLen = str.length();
    for (int i = 0; i < strLen; i++) {
        if (!Character.isWhitespace(str.charAt(i))) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Determines if a character sequence is a QName. A QName is either an
 * NCName (LocalName), or an NCName followed by a colon followed by another
 * NCName (where the first NCName is referred to as the 'Prefix Name' and
 * the second NCName is referred to as the 'Local Name' - i.e.
 * PrefixName:LocalName)./*from ww w. ja  va 2 s  .c  o  m*/
 * 
 * @param s
 *        The character sequence to be tested.
 * @return {@code true} if {@code s} is a QName, otherwise {@code false}.
 */
public static boolean isQName(CharSequence s) {
    if (isNullOrEmpty(s)) {
        return false;
    }
    boolean foundColon = false;
    boolean inNCName = false;
    for (int i = 0; i < s.length();) {
        int codePoint = Character.codePointAt(s, i);
        if (codePoint == ':') {
            if (foundColon) {
                return false;
            }
            foundColon = true;
            if (!inNCName) {
                return false;
            }
            inNCName = false;
        } else {
            if (!inNCName) {
                if (!isXMLNameStartCharacter(codePoint)) {
                    return false;
                }
                inNCName = true;
            } else {
                if (!isXMLNameChar(codePoint)) {
                    return false;
                }
            }
        }
        i += Character.charCount(codePoint);
    }
    return true;
}

From source file:Main.java

/**
 * Determines if a character sequence is a QName.
 * <p>/*from  w ww  . j av a  2  s. c  o m*/
 * A QName is either:
 * <ul>
 * <li>an NCName (LocalName), or</li>
 * <li>an NCName followed by a colon and by another NCName
 * (PrefixName:LocalName)</li>
 * </ul>
 *
 * Source: http://www.w3.org/TR/xml-names/#NT-QName
 *
 * @param s
 *           The character sequence to test.
 * @return Returns <code>true</code> if the character sequence
 *         <code>cs</code> is a QName, or <code>false</code> otherwise.
 */
public static boolean isQName(CharSequence s) {
    if (isEmpty(s)) {
        return false;
    }
    boolean foundColon = false;
    boolean inNCName = false;
    for (int i = 0; i < s.length();) {
        int c = Character.codePointAt(s, i);
        if (c == ':') { //$NON-NLS-1$
            if (foundColon) {
                return false;
            }
            foundColon = true;
            if (!inNCName) {
                return false;
            }
            inNCName = false;
        } else {
            if (!inNCName) {
                if (!isXmlNameStartChar(c)) {
                    return false;
                }
                inNCName = true;
            } else {
                if (!isXmlNameChar(c)) {
                    return false;
                }
            }
        }
        i += Character.charCount(c);
    }
    return true;
}

From source file:Arrays.java

/**
 * Converts the specified character sequence to an array
 * of characters.//from  w  w w  .ja v  a  2  s .  com
 *
 * @param cSeq Character sequence to convert.
 * @return Array of characters in sequence.
 */
public static char[] toArray(CharSequence cSeq) {
    // return cSeq.toString().toCharArray();
    char[] cs = new char[cSeq.length()];
    for (int i = 0; i < cs.length; ++i)
        cs[i] = cSeq.charAt(i);
    return cs;
}

From source file:org.springframework.core.util.StringUtils.java

/**
 * Check whether the given CharSequence has actual text.
 * More specifically, returns <code>true</code> if the string not <code>null</code>,
 * its length is greater than 0, and it contains at least one non-whitespace character.
 * <p><pre>//from  w  w  w  .  j a  va2 s  .com
 * org.springframework.core.util.StringUtils.hasText(null) = false
 * org.springframework.core.util.StringUtils.hasText("") = false
 * org.springframework.core.util.StringUtils.hasText(" ") = false
 * org.springframework.core.util.StringUtils.hasText("12345") = true
 * org.springframework.core.util.StringUtils.hasText(" 12345 ") = true
 * </pre>
 *
 * @param str the CharSequence to check (may be <code>null</code>)
 * @return <code>true</code> if the CharSequence is not <code>null</code>,
 *         its length is greater than 0, and it does not contain whitespace only
 * @see Character#isWhitespace
 */
public static boolean hasText(final CharSequence str) {
    if (!hasLength(str)) {
        return false;
    }
    int strLen = str.length();
    for (int i = 0; i < strLen; i++) {
        if (!Character.isWhitespace(str.charAt(i))) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

static String replaceProperties(final CharSequence string, final Map<String, Object> properties) {
    if (string == null) {
        return null;
    } else {/*from  w w w  .  j a  v a2 s  .c  o  m*/
        final StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < string.length(); ++i) {
            char c = string.charAt(i);
            switch (c) {
            case '$':
                ++i;
                if (i < string.length()) {
                    c = string.charAt(i);
                    if (c == '{') {
                        ++i;
                        final StringBuilder propertyName = new StringBuilder();
                        for (; i < string.length() && c != '}'; ++i) {
                            c = string.charAt(i);
                            if (c != '}') {
                                propertyName.append(c);
                            }
                        }
                        Object value = null;
                        if (propertyName.length() > 0) {
                            value = properties.get(propertyName.toString());

                        }
                        if (value == null) {
                            buffer.append("${");
                            buffer.append(propertyName);
                            buffer.append("}");
                        } else {
                            buffer.append(value);
                        }
                    }
                }
                break;

            default:
                buffer.append(c);
                break;
            }
        }
        return buffer.toString();
    }
}

From source file:edu.mit.mobile.android.livingpostcards.data.Card.java

public static CharSequence getTitle(Context context, Cursor c) {
    CharSequence title = c.getString(c.getColumnIndexOrThrow(Card.COL_TITLE));
    if (title == null || title.length() == 0) {
        title = context.getText(R.string.untitled);
    }/* w  w  w . ja  va 2  s  .  c  o  m*/
    return title;
}

From source file:Main.java

private static Typeface getTextTypeface(final CharSequence text) {
    if (!(text instanceof SpannableString)) {
        return Typeface.DEFAULT;
    }/*from w  ww  . j a v  a2  s  . c o  m*/

    final SpannableString ss = (SpannableString) text;
    final StyleSpan[] styles = ss.getSpans(0, text.length(), StyleSpan.class);
    if (styles.length == 0) {
        return Typeface.DEFAULT;
    }

    if (styles[0].getStyle() == Typeface.BOLD) {
        return Typeface.DEFAULT_BOLD;
    }
    // TODO: BOLD_ITALIC, ITALIC case?
    return Typeface.DEFAULT;
}