Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

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

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:Main.java

/**
 * Green implementation of toCharArray.//from w w w. j  a  v  a  2  s  . c o  m
 *
 * @param cs the {@code CharSequence} to be processed
 * @return the resulting char array
 */
static char[] toCharArray(final CharSequence cs) {
    if (cs instanceof String) {
        return ((String) cs).toCharArray();
    } else {
        final int sz = cs.length();
        final char[] array = new char[cs.length()];
        for (int i = 0; i < sz; i++) {
            array[i] = cs.charAt(i);
        }
        return array;
    }
}

From source file:StringUtils.java

/**
 * @param stripChars if null, remove leading unicode whitespaces.
 *///from  ww  w .  ja v a2  s.c o  m
public static CharSequence stripEnd(CharSequence src, String stripChars) {
    int end;
    if (src == null || (end = src.length()) == 0) {
        return src;
    }
    if (stripChars == null) {
        while ((end != 0) && Character.isWhitespace(src.charAt(end - 1))) {
            end--;
        }
    } else if (stripChars.length() == 0) {
        return src;
    } else {
        while ((end != 0) && (stripChars.indexOf(src.charAt(end - 1)) != -1)) {
            end--;
        }
    }
    return src.subSequence(0, end);
}

From source file:Strings.java

/**
 * Returns the string constructed from the specified character
 * sequence by deaccenting each of its characters.  See {@link
 * #deAccentLatin1(char)} for details of the de-accenting.
 *
 * @param cSeq Character sequence to de accent.
 * @return De-accented version of input.
 *///from   w  w  w. j ava  2s .  com
public static String deAccentLatin1(CharSequence cSeq) {
    char[] cs = new char[cSeq.length()];
    for (int i = 0; i < cs.length; ++i)
        cs[i] = deAccentLatin1(cSeq.charAt(i));
    return new String(cs);
}

From source file:Main.java

/**
 * Test if a format string contains the given designator. Always returns
 * {@code false} if the input format is {@code null}.
 *
 * @hide//w ww .jav  a2 s.  c o  m
 */
public static boolean hasDesignator(CharSequence inFormat, char designator) {
    if (inFormat == null)
        return false;

    final int length = inFormat.length();

    int c;
    int count;

    for (int i = 0; i < length; i += count) {
        count = 1;
        c = inFormat.charAt(i);

        if (c == QUOTE) {
            count = skipQuotedText(inFormat, i, length);
        } else if (c == designator) {
            return true;
        }
    }

    return false;
}

From source file:Main.java

public static String copyString(CharSequence charSequence) {
    int length = charSequence.length();
    char[] chars = new char[length];

    if (charSequence instanceof GetChars) {
        ((GetChars) charSequence).getChars(0, length, chars, 0);
    } else {//from  ww  w .j av  a  2  s. co m
        for (int i = 0; i < length; i++) {
            chars[i] = charSequence.charAt(i);
        }
    }

    return new String(chars);
}

From source file:TextUtils.java

/**
 * Tests if s starts with t, ignoring the case of the characters
 * /*from   w  w w  . j a v a  2 s. c om*/
 * @param s
 * @param t
 * @return <code>true</code> if s.toLowerCase().equals( t.toLowerCase() ),
 *         but more efficiently
 */
public static boolean startsWithIgnoreCase(CharSequence s, CharSequence t) {
    if (s.length() < t.length()) {
        return false;
    }

    for (int i = 0; i < t.length(); i++) {
        char slc = Character.toLowerCase(s.charAt(i));
        char tlc = Character.toLowerCase(t.charAt(i));
        if (slc != tlc) {
            return false;
        }
    }
    return true;
}

From source file:StringUtils.java

/**
 * @param stripChars if null, remove leading unicode whitespaces.
 *///  ww  w  . ja  va2s .  c o m
public static CharSequence stripStart(CharSequence src, String stripChars) {
    int srclen;
    if (src == null || (srclen = src.length()) == 0) {
        return src;
    }
    int start = 0;
    if (stripChars == null) {
        while ((start != srclen) && Character.isWhitespace(src.charAt(start))) {
            start++;
        }
    } else if (stripChars.length() == 0) {
        return src;
    } else {
        while ((start != srclen) && (stripChars.indexOf(src.charAt(start)) != -1)) {
            start++;
        }
    }
    return src.subSequence(start, srclen);
}

From source file:org.diorite.chat.ChatColor.java

public static String getLastColors(final CharSequence input) {
    String result = "";
    final int length = input.length();
    for (int index = length - 1; index > -1; index--) {
        final char section = input.charAt(index);
        if ((section == COLOR_CHAR) && (index < (length - 1))) {
            final char c = input.charAt(index + 1);
            final ChatColor color = getByChar(c);
            if (color != null) {
                result = color.toString() + result;
                if ((color.isColor()) || (color.equals(RESET))) {
                    break;
                }/*  ww w .  j  a va 2s  .  c o m*/
            }
        }
    }
    return result;
}

From source file:net.seleucus.wsp.crypto.FwknopSymmetricCrypto.java

protected static boolean equals(CharSequence a, CharSequence b) {
    if (a.length() != b.length())
        return false;
    boolean result = true;
    for (int i = 0; i < a.length(); i++) {
        if (a.charAt(i) != b.charAt(i))
            result = false;//from  ww  w.  j  a v a  2  s  . c  o  m
    }
    return result;
}

From source file:com.googlecode.jcimd.charset.GsmCharsetProvider.java

/**
 * Returns the number of bytes needed to encode the given character
 * sequence as GSM 3.38 (7-bit) default alphabet. Returns -1 if the
 * given sequence contains a character that cannot be encoded.
 *
 * @param s the given character sequence
 * @return the number of bytes needed to encode the given character
 * sequence as GSM 3.38 (7-bit) default alphabet. Otherwise, -1 is
 * returned./*from  w ww  .j  a  va2  s  .co  m*/
 */
public static int countGsm7BitCharacterBytes(CharSequence s) {
    int length = s.length();
    int totalBits = 0, bits = 0;
    for (int i = 0; i < length; i++) {
        bits = countGsm7BitCharacterBits(s.charAt(i));
        if (bits < 0) {
            return -1;
        }
        totalBits += bits;
    }
    // Divide bits by 8 rounding up
    // (bits + 8 - 1) / 8
    return (totalBits + 7) / 8;
}