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:eu.stratosphere.types.StringValue.java

public static final void writeString(CharSequence cs, DataOutput out) throws IOException {
    if (cs != null) {
        // the length we write is offset by one, because a length of zero indicates a null value
        int lenToWrite = cs.length() + 1;
        if (lenToWrite < 0) {
            throw new IllegalArgumentException("CharSequence is too long.");
        }// ww  w . ja v  a  2 s.c om

        // write the length, variable-length encoded
        while (lenToWrite >= HIGH_BIT) {
            out.write(lenToWrite | HIGH_BIT);
            lenToWrite >>>= 7;
        }
        out.write(lenToWrite);

        // write the char data, variable length encoded
        for (int i = 0; i < cs.length(); i++) {
            int c = cs.charAt(i);

            while (c >= HIGH_BIT) {
                out.write(c | HIGH_BIT);
                c >>>= 7;
            }
            out.write(c);
        }
    } else {
        out.write(0);
    }
}

From source file:org.exist.util.Base64Decoder.java

/**
 * Decode the base 64 string into a byte array (which can subsequently be accessed using getByteArray()
 * @param str the base 64 string/*from  w ww . j a v a2 s  . c  o m*/
 * @throws IllegalArgumentException if the base64 string is incorrectly formatted
 */

public final void translate(CharSequence str) throws IllegalArgumentException {
    if (token == null) // already saw eof marker?
    {
        return;
    }
    final int length = str.length();
    int lengthAtEOF;
    int found_eq = 0;
    for (int i = 0; i < length; i++) {
        final char c = str.charAt(i);
        if (c > 127) {
            throw new IllegalArgumentException("non-ASCII character in Base64 value (at offset " + i + ')');
        }
        byte t = map[c];
        if (t == NUL) {
            throw new IllegalArgumentException(
                    "invalid character '" + c + "' in Base64 value (at offset " + i + ')');
        }
        if (found_eq > 0 && t != EOF && t != SP) {
            throw new IllegalArgumentException("In Base64, an '=' character can appear only at the end");
        }
        if (t == EOF) {
            if (found_eq > 0) {
                found_eq++;
                if (found_eq > 2) {
                    throw new IllegalArgumentException("Base64 value can contain at most two '=' characters");
                }
                token_length = (token_length + 1) % 4;
            } else {
                found_eq = 1;
                lengthAtEOF = token_length;
                eof();
                token_length = (lengthAtEOF + 1) % 4;
            }
        } else if (t != SP) {
            token[token_length++] = t;
            if (token_length == 4) {
                if (found_eq == 0) {
                    decode_token();
                }
                token_length = 0;
            }
        }
    }
    if (token_length != 0) {
        throw new IllegalArgumentException("Base64 input must be a multiple of four characters");
    }
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static boolean hasAccents(final CharSequence sequence) {
    if (isBlankOrNull(sequence)) {
        return false;
    }// ww  w.  j ava 2 s .  co m
    for (int i = 0; i < sequence.length(); i++) {
        char c = sequence.charAt(i);
        if (LatinCharacterUtils.isDecoratedLetter(c)) {
            return true;
        }
    }
    return false;
}

From source file:org.cnc.mombot.utils.ContactsEditText.java

private void init(Context context) {
    // Set image height
    mDropdownItemHeight = 48;//from   w ww.  j  a v a2 s . com

    // Set default image
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_contact_picture_holo_light, options);
    options.inSampleSize = Utils.calculateInSampleSize(options, mDropdownItemHeight, mDropdownItemHeight);
    options.inJustDecodeBounds = false;
    mLoadingImage = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.ic_contact_picture_holo_light, options);

    // Set adapter
    mAdapter = new ContactsAdapter(context);
    setAdapter(mAdapter);
    mAdapter.swapCursor(mAdapter.runQueryOnBackgroundThread(""));

    // Separate entries by commas
    setTokenizer(new Tokenizer() {

        @Override
        public CharSequence terminateToken(CharSequence text) {
            int i = text.length();

            while (i > 0 && text.charAt(i - 1) == ' ') {
                i--;
            }

            if (i > 0 && text.charAt(i - 1) == ' ') {
                return text;
            } else {
                if (text instanceof Spanned) {
                    SpannableString sp = new SpannableString(text + " ");
                    TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
                    return sp;
                } else {
                    return text + " ";
                }
            }
        }

        @Override
        public int findTokenStart(CharSequence text, int cursor) {
            int i = cursor;

            while (i > 0 && text.charAt(i - 1) != ' ') {
                i--;
            }
            // Check if token really started with ' ', else we don't have a valid token
            if (i < 1 || text.charAt(i - 1) != ' ') {
                return cursor;
            }

            return i;
        }

        @Override
        public int findTokenEnd(CharSequence text, int cursor) {
            int i = cursor;
            int len = text.length();

            while (i < len) {
                if (text.charAt(i) == ' ') {
                    return i;
                } else {
                    i++;
                }
            }

            return len;
        }
    });

    // Pop up suggestions after 1 character is typed.
    setThreshold(1);

    setOnClickListener(this);
    setOnFocusChangeListener(this);
}

From source file:org.multibit.crypto.KeyCrypterOpenSSL.java

/**
 * Convert a CharSequence (which are UTF16) into a char array.
 *
 * Note: a String.getBytes() is not used to avoid creating a String of the password in the JVM.
 */// w  w  w.j  a v a 2s. c  om
private char[] convertToCharArray(CharSequence charSequence) {
    if (charSequence == null) {
        return null;
    }

    char[] charArray = new char[charSequence.length()];
    for (int i = 0; i < charSequence.length(); i++) {
        charArray[i] = charSequence.charAt(i);
    }
    return charArray;
}

From source file:org.opendatakit.services.preferences.fragments.ServerSettingsFragment.java

/**
 * Disallows carriage returns from user entry
 *
 * @return// w  w  w  .j a v  a2  s  .  com
 */
private InputFilter getReturnFilter() {
    InputFilter returnFilter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            for (int i = start; i < end; i++) {
                if (Character.getType((source.charAt(i))) == Character.CONTROL) {
                    return "";
                }
            }
            return null;
        }
    };
    return returnFilter;
}

From source file:org.opendatakit.services.preferences.fragments.ServerSettingsFragment.java

/**
 * Disallows whitespace from user entry// w ww  .  j a v a  2  s  .com
 *
 * @return
 */
private InputFilter getWhitespaceFilter() {
    InputFilter whitespaceFilter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            for (int i = start; i < end; i++) {
                if (Character.isWhitespace(source.charAt(i))) {
                    return "";
                }
            }
            return null;
        }
    };
    return whitespaceFilter;
}

From source file:org.jbpm.designer.web.profile.impl.JbpmProfileImpl.java

private boolean isEmpty(final CharSequence str) {
    if (str == null || str.length() == 0) {
        return true;
    }//  w  w  w .ja  v a2s .c  om
    for (int i = 0, length = str.length(); i < length; i++) {
        if (str.charAt(i) != ' ') {
            return false;
        }
    }
    return true;
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static int countRepetitionChain(final CharSequence sequence) {
    if (length(sequence) < 2) {
        return length(sequence);
    }/*from   w w  w  .ja  v a  2  s.c o m*/
    int max = 1;
    int count = 1;
    char lookupChar = sequence.charAt(0);
    for (int i = 1; i < sequence.length(); i++) {
        if (sequence.charAt(i) == lookupChar) {
            count++;
        } else {
            lookupChar = sequence.charAt(i);
            if (count > max) {
                max = count;
            }
            count = 1;
        }
    }
    if (count > max) {
        max = count;
    }
    return max;
}

From source file:org.power.commons.lang.util.internal.IndentableStringBuilder.java

/**
 * <code>Appendable</code>?/*from   w w w.  j a va 2s .  c o  m*/
 */
public final B append(CharSequence csq, int start, int end) {
    for (int i = start; i < end; i++) {
        append(csq.charAt(i));
    }

    return thisObject();
}