Java XML Parse String parseArray(String inputArray)

Here you can find the source of parseArray(String inputArray)

Description

parse Array

License

GNU General Public License

Declaration

public static String[] parseArray(String inputArray) 

Method Source Code


//package com.java2s;
/*/*from w  w w .  jav a  2s  .  co  m*/
 *
 *    AWTRY (Another Way To Read YAML) - YAML reader for Java.
 *     Copyright (C) 2015 TheRealBuggy/JonathanxD (Jonathan Ribeiro Lopes) <jonathan.scripter@programmer.net>
 *
 *    GNU GPLv3
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Affero General Public License as published
 *     by the Free Software Foundation.
 *
 *     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 Affero General Public License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;

public class Main {
    public static String[] parseArray(String inputArray) {
        ArrayList<String> result = new ArrayList<String>();

        int start = 0;
        boolean quote = false;

        for (int x = 0; x < inputArray.length(); x++) {
            if (inputArray.charAt(x) == '\"')
                quote = !quote;

            boolean lastChar = (x == inputArray.length() - 1);

            if (lastChar) {
                result.add(inputArray.substring(start).trim());
            } else if (inputArray.charAt(x) == ',' && !quote) {
                result.add(inputArray.substring(start, x).trim());
                start = x + 1;
            }
        }
        return result.toArray(new String[result.size()]);
    }
}

Related

  1. parseArguments(String[] arguments, String delimiter)
  2. parseArgumentString(String argStr)
  3. parseArgumentString(String command)
  4. parseArray(String array)
  5. parseArray(String array)
  6. parseXml(Object obj)
  7. parseXML(String path)
  8. parseXML(String pathToMap)
  9. parseXML(String resp, String name)