Java String Match regionMatches(CharSequence seq, int toff, CharSequence other, int ooff, int len)

Here you can find the source of regionMatches(CharSequence seq, int toff, CharSequence other, int ooff, int len)

Description

Implementation of String.regionMatches() for CharSequence.

License

Open Source License

Parameter

Parameter Description
seq The test CharSequence.
toff Offset for the test sequence.
other The sequence to compare to.
ooff Offset of the comparison sequence.
len How many characters to compare.

Return

Whether the two subsequences are equal.

Declaration

public static boolean regionMatches(CharSequence seq, int toff, CharSequence other, int ooff, int len) 

Method Source Code

//package com.java2s;
/*/*w  ww  .  jav a 2 s. co m*/
 * StandardUtilities.java - Various miscallaneous utility functions
 * :tabSize=4:indentSize=4:noTabs=false:
 * :folding=explicit:collapseFolds=1:
 *
 * Copyright (C) 1999, 2006 Matthieu Casanova, Slava Pestov
 * Portions copyright (C) 2000 Richard S. Hall
 * Portions copyright (C) 2001 Dirk Moebius
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

public class Main {
    /**
     * Implementation of String.regionMatches() for CharSequence.
     *
     * @param seq The test CharSequence.
     * @param toff Offset for the test sequence.
     * @param other The sequence to compare to.
     * @param ooff Offset of the comparison sequence.
     * @param len How many characters to compare.
     * @return Whether the two subsequences are equal.
     * @see String#regionMatches(int,String,int,int)
     *
     * @since jEdit 4.3pre15
     */
    public static boolean regionMatches(CharSequence seq, int toff, CharSequence other, int ooff, int len) {

        if (toff < 0 || ooff < 0 || len < 0)
            return false;

        boolean ret = true;
        for (int i = 0; i < len; i++) {
            char c1;

            if (i + toff < seq.length())
                c1 = seq.charAt(i + toff);
            else {
                ret = false;
                break;
            }

            char c2;
            if (i + ooff < other.length())
                c2 = other.charAt(i + ooff);
            else {
                ret = false;
                break;
            }

            if (c1 != c2) {
                ret = false;
                break;
            }
        }

        return ret;
    }
}

Related

  1. regionMatches(char[] source, char[] target, int sIndex)
  2. regionMatches(CharSequence a, int i, CharSequence b, int j, int len)
  3. regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length)
  4. regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length)
  5. regionMatches(CharSequence receiver, int thisOffset, String other, int otherOffset, int length, boolean ignoreCase)
  6. regionMatches(final char[] content, final int index, final String tag)
  7. regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, final CharSequence substring, final int start, final int length)
  8. regionMatches(final CharSequence seq1, final int start1, final CharSequence seq2, final int start2, final int len, final boolean ignoreCase)
  9. regionMatches(String string, int toffset, StringBuffer other, int ooffset, int len)