android.text.GetChars Java Examples

The following examples show how to use android.text.GetChars. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextUtils.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
public static void getChars(CharSequence s, int start, int end,
                            char[] dest, int destoff) {
    Class c = s.getClass();

    if (c == String.class)
        ((String) s).getChars(start, end, dest, destoff);
    else if (c == StringBuffer.class)
        ((StringBuffer) s).getChars(start, end, dest, destoff);
    else if (c == StringBuilder.class)
        ((StringBuilder) s).getChars(start, end, dest, destoff);
    else if (s instanceof GetChars)
        ((GetChars) s).getChars(start, end, dest, destoff);
    else {
        for (int i = start; i < end; i++)
            dest[destoff++] = s.charAt(i);
    }
}
 
Example #2
Source File: TextUtils.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
public static void getChars(CharSequence s, int start, int end,
                            char[] dest, int destoff) {
    Class c = s.getClass();

    if (c == String.class)
        ((String) s).getChars(start, end, dest, destoff);
    else if (c == StringBuffer.class)
        ((StringBuffer) s).getChars(start, end, dest, destoff);
    else if (c == StringBuilder.class)
        ((StringBuilder) s).getChars(start, end, dest, destoff);
    else if (s instanceof GetChars)
        ((GetChars) s).getChars(start, end, dest, destoff);
    else {
        for (int i = start; i < end; i++)
            dest[destoff++] = s.charAt(i);
    }
}
 
Example #3
Source File: TextUtils.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
public static int indexOf(CharSequence s, char ch, int start, int end) {
    Class c = s.getClass();

    if (s instanceof GetChars || c == StringBuffer.class ||
        c == StringBuilder.class || c == String.class) {
        final int INDEX_INCREMENT = 500;
        char[] temp = obtain(INDEX_INCREMENT);

        while (start < end) {
            int segend = start + INDEX_INCREMENT;
            if (segend > end)
                segend = end;

            getChars(s, start, segend, temp, 0);

            int count = segend - start;
            for (int i = 0; i < count; i++) {
                if (temp[i] == ch) {
                    recycle(temp);
                    return i + start;
                }
            }

            start = segend;
        }

        recycle(temp);
        return -1;
    }

    for (int i = start; i < end; i++)
        if (s.charAt(i) == ch)
            return i;

    return -1;
}
 
Example #4
Source File: StringUtils.java    From Tehreer-Android with Apache License 2.0 5 votes vote down vote up
public static @NonNull String copyString(@NonNull CharSequence charSequence) {
    int length = charSequence.length();
    char[] chars = new char[length];

    if (charSequence instanceof GetChars) {
        ((GetChars)charSequence).getChars(0, length, chars, 0);
    } else {
        for (int i = 0; i < length; i++) {
            chars[i] = charSequence.charAt(i);
        }
    }

    return new String(chars);
}
 
Example #5
Source File: TextUtils.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
public static int indexOf(CharSequence s, char ch, int start, int end) {
    Class c = s.getClass();

    if (s instanceof GetChars || c == StringBuffer.class ||
        c == StringBuilder.class || c == String.class) {
        final int INDEX_INCREMENT = 500;
        char[] temp = obtain(INDEX_INCREMENT);

        while (start < end) {
            int segend = start + INDEX_INCREMENT;
            if (segend > end)
                segend = end;

            getChars(s, start, segend, temp, 0);

            int count = segend - start;
            for (int i = 0; i < count; i++) {
                if (temp[i] == ch) {
                    recycle(temp);
                    return i + start;
                }
            }

            start = segend;
        }

        recycle(temp);
        return -1;
    }

    for (int i = start; i < end; i++)
        if (s.charAt(i) == ch)
            return i;

    return -1;
}
 
Example #6
Source File: TextUtils.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
public static int lastIndexOf(CharSequence s, char ch,
                              int start, int last) {
    if (last < 0)
        return -1;
    if (last >= s.length())
        last = s.length() - 1;

    int end = last + 1;

    Class c = s.getClass();

    if (s instanceof GetChars || c == StringBuffer.class ||
        c == StringBuilder.class || c == String.class) {
        final int INDEX_INCREMENT = 500;
        char[] temp = obtain(INDEX_INCREMENT);

        while (start < end) {
            int segstart = end - INDEX_INCREMENT;
            if (segstart < start)
                segstart = start;

            getChars(s, segstart, end, temp, 0);

            int count = end - segstart;
            for (int i = count - 1; i >= 0; i--) {
                if (temp[i] == ch) {
                    recycle(temp);
                    return i + segstart;
                }
            }

            end = segstart;
        }

        recycle(temp);
        return -1;
    }

    for (int i = end - 1; i >= start; i--)
        if (s.charAt(i) == ch)
            return i;

    return -1;
}
 
Example #7
Source File: TextUtils.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
public static int lastIndexOf(CharSequence s, char ch,
                              int start, int last) {
    if (last < 0)
        return -1;
    if (last >= s.length())
        last = s.length() - 1;

    int end = last + 1;

    Class c = s.getClass();

    if (s instanceof GetChars || c == StringBuffer.class ||
        c == StringBuilder.class || c == String.class) {
        final int INDEX_INCREMENT = 500;
        char[] temp = obtain(INDEX_INCREMENT);

        while (start < end) {
            int segstart = end - INDEX_INCREMENT;
            if (segstart < start)
                segstart = start;

            getChars(s, segstart, end, temp, 0);

            int count = end - segstart;
            for (int i = count - 1; i >= 0; i--) {
                if (temp[i] == ch) {
                    recycle(temp);
                    return i + segstart;
                }
            }

            end = segstart;
        }

        recycle(temp);
        return -1;
    }

    for (int i = end - 1; i >= start; i--)
        if (s.charAt(i) == ch)
            return i;

    return -1;
}