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

/**
 * Tells whether has a flag in the same line as mentioned by fromIndex character.
 * @param sequence - text/*w  w w.  j  a v  a2  s .c  o m*/
 * @param flag - expected flag.
 * @param fromIndex - index representing the line.
 * @return
 */
public static boolean hasFlagSameLine(CharSequence sequence, char flag, int fromIndex) {

    for (int i = fromIndex; i < sequence.length(); i++) {
        char c = sequence.charAt(i);
        if (c == NEW_LINE) {
            return false;
        }

        if (c == flag) {
            return i != fromIndex;
        }
    }

    return false;
}

From source file:Main.java

/**
 * Get the longest NCName that is a suffix of a character sequence.
 * //ww w.  j  av a2 s . c  o m
 * @param s
 *        The character sequence.
 * @return The String which is the longest suffix of the character sequence
 *         {@code s} that is an NCName, or {@code null} if the character
 *         sequence {@code s} does not have a suffix that is an NCName.
 */
@Nullable
public static String getNCNameSuffix(CharSequence s) {
    if (s.length() > 1 && s.charAt(0) == '_' && s.charAt(1) == ':') {
        return null;
    }
    int localPartStartIndex = getNCNameSuffixIndex(s);
    if (localPartStartIndex > -1) {
        return s.toString().substring(localPartStartIndex);
    } else {
        return null;
    }
}

From source file:StandardUtilities.java

/**
 * Returns the number of leading white space characters in the
 * specified string./*from   www .ja  va  2s. c  o  m*/
 *
 * @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 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 . j  ava  2s.  c om*/
    }
    return true;
}

From source file:Main.java

/**
 * Test whether the given string matches the given substring
 * at the given index.//from  www  . j  a  v a 2 s  . co  m
 * @param str the original string (or StringBuilder)
 * @param index the index in the original string to start matching against
 * @param substring the substring to match at the given index
 */
public static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
    for (int j = 0; j < substring.length(); j++) {
        int i = index + j;
        if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * @since 4.4//from  www  .  j av a2 s . c o 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

/**
 * Returns true if the parameter is null or contains only whitespace
 *///  www  .j av a2s  . com
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:StandardUtilities.java

/**
 * Returns the width of the leading white space in the specified
 * string.// w ww  .j  a v a2 s .com
 * @param str The string
 * @param tabSize The tab size
 * @since jEdit 4.3pre15
 */
public static int getLeadingWhiteSpaceWidth(CharSequence str, int tabSize) {
    int whitespace = 0;
    loop: for (int i = 0; i < str.length(); i++) {
        switch (str.charAt(i)) {
        case ' ':
            whitespace++;
            break;
        case '\t':
            whitespace += tabSize - whitespace % tabSize;
            break;
        default:
            break loop;
        }
    }
    return whitespace;
}

From source file:Main.java

public static CharSequence getJellyBeanFix(CharSequence input) {
    ArrayList<Integer> resultList = new ArrayList<Integer>();

    for (int i = 0; i < input.length(); i++) {
        int iValue = (int) input.charAt(i);
        if (iValue == 0x1031) {
            resultList.add(JBFIX_CHAR);/*from w  w  w.  j a va2s .c  o  m*/
            resultList.add(iValue);
        } else if (iValue == 0x1039) {
            resultList.add(iValue);
            resultList.add(JBFIX_CHAR);
        } else {
            resultList.add(iValue);
        }
    }

    char[] chArray = new char[resultList.size()];
    int count = 0;
    for (Integer ch : resultList) {
        chArray[count++] = (char) ch.intValue();
    }

    return String.valueOf(chArray);
}

From source file:Main.java

public static boolean isMyChar(CharSequence label) {
    if (label == null)
        return false;
    boolean isMyChar = false;
    for (int i = 0; i < label.length(); i++) {
        if (isMyChar(label.charAt(i))) {
            isMyChar = true;/*  ww  w  . j  a  v a  2s .c  o m*/
            break;
        }
    }
    return isMyChar;
}