Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

public class Main {
    /**
     * Return true if the string starting at offset in sb matches with xmlTag.
     * @param sb StringBuffer
     * @param offset int
     * @param xmlTag String The XML tag name to check without '<' and '>'
     * @return
     */
    private static boolean matchXMLTag(StringBuffer sb, int offset, String xmlTag) {
        if (offset >= sb.length()) {
            return false;
        }
        if (sb.charAt(offset) != '<') {
            return false;
        }
        int indexOfSpace = sb.indexOf(" ", offset);
        int indexOfGt = sb.indexOf(">", offset);
        int indexOfEndTag = Integer.MAX_VALUE;
        if (indexOfSpace >= 0) {
            indexOfEndTag = indexOfSpace;
        }
        if (indexOfGt >= 0 && indexOfGt < indexOfEndTag) {
            indexOfEndTag = indexOfGt;
        }
        if (indexOfEndTag == Integer.MAX_VALUE) {
            return false;
        }
        String potentialTag = sb.substring(offset + 1, indexOfEndTag);
        return potentialTag.equals(xmlTag);
    }
}