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:Main.java

/**
 * Determine if two character sequences contain the same characters.
 *
 * @param cs1//from   www .j  a va 2  s. co m
 *     first character sequence
 * @param cs2
 *     second character sequence
 * @return true if both sequences have same length and same character sequence
 */
public static boolean isSameSequence(CharSequence cs1, CharSequence cs2) {
    assert cs1 != null;
    assert cs2 != null;
    if (cs1.length() != cs2.length()) {
        return false;
    } else {
        for (int i = 0, n = cs1.length(); i < n; i++) {
            if (cs1.charAt(i) != cs2.charAt(i)) {
                return false;
            }
        }
        return true;
    }
}

From source file:StringUtils.java

/**
 * @param stripChars if null, remove leading unicode whitespaces.
 *//* w ww  .  jav a 2  s.c  o m*/
public static CharSequence strip(CharSequence src, String stripChars) {
    if (src == null || src.length() == 0) {
        return src;
    }
    final CharSequence striped = stripStart(src, stripChars);
    return stripEnd(striped, stripChars);
}

From source file:Main.java

/**
 * Returns true if the parameter is null or contains only whitespace
 *//*w ww  .j  a v a 2 s.  c  om*/
public static boolean isBlank(final CharSequence s) {
    if (s == null) {
        return true;
    }
    for (int i = 0; i < s.length(); i++) {
        if (!Character.isWhitespace(s.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * @since 4.4/*from   ww  w  .j  a  v a  2 s  .  co  m*/
 */
public static boolean containsBlanks(final CharSequence s) {
    if (s == null) {
        return false;
    }
    for (int i = 0; i < s.length(); i++) {
        if (Character.isWhitespace(s.charAt(i))) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static CharSequence small(CharSequence sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}

From source file:StandardUtilities.java

/**
 * Returns the number of leading white space characters in the
 * specified string./*  www  . java  2s.com*/
 *
 * @param str The string
 * @since jEdit 4.3pre15
 */
public static int getLeadingWhiteSpace(CharSequence str) {
    int whitespace = 0;
    loop: for (; whitespace < str.length();) {
        switch (str.charAt(whitespace)) {
        case ' ':
        case '\t':
            whitespace++;
            break;
        default:
            break loop;
        }
    }
    return whitespace;
}

From source file:Main.java

public static CharSequence color(int color, CharSequence sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new ForegroundColorSpan(color), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}

From source file:Main.java

public static CharSequence bold(CharSequence sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}

From source file:Main.java

/**
 * utility to get the part of a charsequence that is not the NCName
 * fragment./* w  w  w.java2s.  com*/
 * 
 * @param s
 *        the charsequence to split
 * @return the prefix split at the last non-ncname character, or the whole
 *         input if no ncname is found
 */
public static String getNCNamePrefix(CharSequence s) {
    if (s.length() > 1 && s.charAt(0) == '_' && s.charAt(1) == ':') {
        return s.toString();
    }
    int localPartStartIndex = getNCNameSuffixIndex(s);
    if (localPartStartIndex > -1) {
        return s.toString().substring(0, localPartStartIndex);
    } else {
        return s.toString();
    }
}

From source file:Main.java

public static boolean isEmpty(CharSequence input) {
    if (input == null || "".equals(input))
        return true;

    for (int i = 0; i < input.length(); i++) {
        char c = input.charAt(i);
        if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
            return false;
        }//from  ww w  .ja  v a 2  s.c  o m
    }
    return true;
}