Compares the two character sequences in the buffer at the positions until a not escaped '=' is found. - Java java.nio

Java examples for java.nio:ByteBuffer Char

Description

Compares the two character sequences in the buffer at the positions until a not escaped '=' is found.

Demo Code

/*************************************************************************
 *                                                                       *
 *  EJBCA: The OpenSource Certificate Authority                          *
 *                                                                       *
 *  This software is free software; you can redistribute it and/or       *
 *  modify it under the terms of the GNU Lesser General Public           *
 *  License as published by the Free Software Foundation; either         *
 *  version 2.1 of the License, or any later version.                    *
 *                                                                       *
 *  See terms of license at gnu.org.                                     *
 *                                                                       *
 *************************************************************************/
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;

public class Main{
    /** Compares the two character sequences in the buffer at the positions until a not escaped '=' is found. */
    private static boolean hasSameKey(final char[] sb, int pos1, int pos2) {
        final int len = sb.length;
        boolean notEscaped = true; // Keep track of what is escapes and not
        while (len > pos1 && len > pos2) {
            final char c1 = sb[pos1];
            switch (c1) {
            case '\\':
                notEscaped ^= true;/*from www  .  j ava  2  s .  co  m*/
                break;
            case '=':
                if (notEscaped && c1 == sb[pos2]) {
                    return true;
                } // else.. continue with the default action..
            default:
                if (c1 != sb[pos2]) {
                    return false;
                }
                notEscaped = true;
            }
            pos1++;
            pos2++;
        }
        return false;
    }
}

Related Tutorials