Java String Match regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, final CharSequence substring, final int start, final int length)

Here you can find the source of regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, final CharSequence substring, final int start, final int length)

Description

region Matches

License

Open Source License

Declaration

static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart,
            final CharSequence substring, final int start, final int length) 

Method Source Code

//package com.java2s;

public class Main {
    static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart,
            final CharSequence substring, final int start, final int length) {
        if (cs instanceof String && substring instanceof String) {
            return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length);
        }/*w  ww.  j a v  a2  s  .  c om*/

        int index1 = thisStart;
        int index2 = start;
        int tmpLen = length;

        while (tmpLen-- > 0) {
            char c1 = cs.charAt(index1++);
            char c2 = substring.charAt(index2++);

            if (c1 == c2) {
                continue;
            }

            if (!ignoreCase) {
                return false;
            }

            // The same check as in String.regionMatches():
            if (Character.toUpperCase(c1) != Character.toUpperCase(c2)
                    && Character.toLowerCase(c1) != Character.toLowerCase(c2)) {
                return false;
            }
        }

        return true;

    }
}

Related

  1. regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length)
  2. regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length)
  3. regionMatches(CharSequence receiver, int thisOffset, String other, int otherOffset, int length, boolean ignoreCase)
  4. regionMatches(CharSequence seq, int toff, CharSequence other, int ooff, int len)
  5. regionMatches(final char[] content, final int index, final String tag)
  6. regionMatches(final CharSequence seq1, final int start1, final CharSequence seq2, final int start2, final int len, final boolean ignoreCase)
  7. regionMatches(String string, int toffset, StringBuffer other, int ooffset, int len)
  8. regionMatchesIgnoreCase(char[] string, int toffset, String other, int ooffset, int len)