Here you can find the source of parseArguments(String[] arguments, String delimiter)
Parameter | Description |
---|---|
arguments | the arguments to sanitize |
delimiter | the delimiter to insert in between the elements in quotes (ie: " ") |
public static String[] parseArguments(String[] arguments, String delimiter)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**/*from w ww .ja va 2 s . c o m*/ * Parses an array of string arguments so that things wrapped in quotes count as one element in the array. * * @param arguments the arguments to sanitize * @param delimiter the delimiter to insert in between the elements in quotes (ie: " ") * @return the sanitized array of string arguments */ public static String[] parseArguments(String[] arguments, String delimiter) { List<String> sanitized = new ArrayList<>(); for (int i = 0; i < arguments.length; i++) { if (arguments[i].startsWith("\"")) { StringBuilder buffer = new StringBuilder(); buffer.append(arguments[i].substring("\"".length())); buffer.append(delimiter); for (i++; i < arguments.length; i++) { if (arguments[i].endsWith("\"")) { buffer.append(arguments[i].substring(0, arguments[i].length() - "\"".length())); buffer.append(delimiter); break; } else { buffer.append(arguments[i]); buffer.append(delimiter); } } sanitized.add(buffer.toString()); } else { sanitized.add(arguments[i]); } } return sanitized.toArray(new String[0]); } }