Java XML Parse String parseArgs(String text)

Here you can find the source of parseArgs(String text)

Description

parse Args

License

Open Source License

Declaration

static public List<String> parseArgs(String text) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    static public List<String> parseArgs(String text) {

        List<String> args = new ArrayList<String>();

        boolean inQuotes = false;
        boolean inEscape = false;

        StringBuilder element = new StringBuilder();

        char[] charArray = text.toCharArray();
        for (int i = 0; i < charArray.length; i++) {

            char c = charArray[i];

            if (c == '"' && !inEscape) {
                inQuotes = !inQuotes; //Toggle on/off inQuotes
                continue;
            }/* w w  w  .j  a va 2s.  com*/

            if (!inQuotes && c == ' ') {
                args.add(element.toString());
                element = new StringBuilder();
                continue;
            }

            if (c == '\\' && !inEscape) {
                inEscape = true;
                continue;
            } else {
                inEscape = false;
            }

            element.append(c);

        }

        if (!element.toString().equalsIgnoreCase("")) {
            args.add(element.toString());
        }

        return args;

    }
}

Related

  1. parse(String xml)
  2. parse(String xml)
  3. parseAccessNumber(String line)
  4. parseAddressLines(String[] addressLines)
  5. parseArg(String arg)
  6. parseArgs(String[] args)
  7. parseArgs(String[] args)
  8. parseArgsString(String args)
  9. parseArgsToVmArgs(String[] args, String prefixOfVmArgs)