Java String Split split(String signature, boolean skipInitialAngleBracket)

Here you can find the source of split(String signature, boolean skipInitialAngleBracket)

Description

split

License

Open Source License

Declaration

public static final List<String> split(String signature, boolean skipInitialAngleBracket) 

Method Source Code


//package com.java2s;
/*/*w w  w .j a  v  a 2  s. c om*/
 * FindBugs - Find Bugs in Java programs
 * Copyright (C) 2006, University of Maryland
 *
 * This library 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 (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static final List<String> split(String signature, boolean skipInitialAngleBracket) {
        List<String> result = new ArrayList<>();
        if (signature.charAt(0) != '<') {
            skipInitialAngleBracket = false;
        }
        int depth = 0;
        int start = 0;
        for (int pos = start; pos < signature.length(); pos++) {
            switch (signature.charAt(pos)) {
            case '<':
                depth++;
                break;
            case '>':
                depth--;
                if (depth == 0 && skipInitialAngleBracket) {
                    skipInitialAngleBracket = false;
                    start = pos + 1;
                }
                break;
            case ';':
                if (depth > 0) {
                    break;
                }
                String substring = signature.substring(start, pos + 1);
                result.add(substring);
                start = pos + 1;
                break;
            default:
                break;
            }
        }
        if (depth != 0) {
            throw new IllegalArgumentException("Unbalanced signature: " + signature);
        }
        return result;
    }
}

Related

  1. split(String s, String seperator)
  2. split(String s, String spliter, boolean removeEmptyItem)
  3. split(String s, String splitStr)
  4. split(String s, String splitter)
  5. split(String self)
  6. split(String source, String seperator)
  7. split(String str)
  8. split(String str)
  9. split(String str)