Java String Index Of indexOfIgnoreCase(final String src, char c, int startIndex, int endIndex)

Here you can find the source of indexOfIgnoreCase(final String src, char c, int startIndex, int endIndex)

Description

index Of Ignore Case

License

Open Source License

Declaration

public static int indexOfIgnoreCase(final String src, char c, int startIndex, int endIndex) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static int indexOfIgnoreCase(final String src, char c, int startIndex, int endIndex) {
        if (startIndex < 0) {
            startIndex = 0;/*from   w w  w  .j  a  va  2  s. co m*/
        }
        final int srclen = src.length();
        if (endIndex > srclen) {
            endIndex = srclen;
        }
        c = Character.toLowerCase(c);
        for (int i = startIndex; i < endIndex; ++i) {
            if (Character.toLowerCase(src.charAt(i)) == c) {
                return i;
            }
        }
        return -1;
    }

    public static int indexOfIgnoreCase(final String src, final String subS) {
        return indexOfIgnoreCase(src, subS, 0, src.length());
    }

    public static int indexOfIgnoreCase(final String src, final String subS, final int startIndex) {
        return indexOfIgnoreCase(src, subS, startIndex, src.length());
    }

    public static int indexOfIgnoreCase(final String src, String sub, int startIndex, int endIndex) {
        if (startIndex < 0) {
            startIndex = 0;
        }
        final int srclen = src.length();
        if (endIndex > srclen) {
            endIndex = srclen;
        }
        final int sublen = sub.length();
        if (sublen == 0) {
            return (startIndex > srclen) ? srclen : startIndex;
        }
        sub = sub.toLowerCase();
        final int total = endIndex - sublen + 1;
        final char c = sub.charAt(0);
        Label_0145: for (int i = startIndex; i < total; ++i) {
            if (Character.toLowerCase(src.charAt(i)) == c) {
                for (int j = 1, k = i + 1; j < sublen; ++j, ++k) {
                    final char source = Character.toLowerCase(src.charAt(k));
                    if (sub.charAt(j) != source) {
                        continue Label_0145;
                    }
                }
                return i;
            }
        }
        return -1;
    }

    public static int[] indexOfIgnoreCase(final String s, final String[] arr) {
        return indexOfIgnoreCase(s, arr, 0);
    }

    public static int[] indexOfIgnoreCase(final String s, final String[] arr, final int start) {
        final int arrLen = arr.length;
        int index = Integer.MAX_VALUE;
        int last = -1;
        for (int j = 0; j < arrLen; ++j) {
            final int i = indexOfIgnoreCase(s, arr[j], start);
            if (i != -1 && i < index) {
                index = i;
                last = j;
            }
        }
        int[] array;
        if (last == -1) {
            array = null;
        } else {
            final int[] array2 = array = new int[2];
            array2[0] = last;
            array2[1] = index;
        }
        return array;
    }

    public static String toLowerCase(final String s) {
        return toLowerCase(s, null);
    }

    public static String toLowerCase(final String s, Locale locale) {
        if (s == null) {
            return null;
        }
        StringBuilder sb = null;
        for (int i = 0; i < s.length(); ++i) {
            final char c = s.charAt(i);
            if (c > '\u007f') {
                if (locale == null) {
                    locale = Locale.getDefault();
                }
                return s.toLowerCase(locale);
            }
            if (c >= 'A' && c <= 'Z') {
                if (sb == null) {
                    sb = new StringBuilder(s);
                }
                sb.setCharAt(i, (char) (c + ' '));
            }
        }
        if (sb == null) {
            return s;
        }
        return sb.toString();
    }

    public static String toString(final Object value) {
        if (value == null) {
            return null;
        }
        return value.toString();
    }
}

Related

  1. getStructValue(String struct, int index)
  2. getTabIndexes(String text)
  3. getUserGroupsFromImpex( final String impexContent, final int uidIndex)
  4. indexOf(final String str, final String searchString)
  5. indexOfClosingBracket(String text, int openingBracket)
  6. indexOfIgnoreCase(String str, String substring)
  7. indexOfMultiple(String line, char character, int count, int startIndex)
  8. indexOfWord(String word, String string)
  9. isPhaseGroupContainsPhase(int index, String phaseName)