All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.plugin.tools.util.Utils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */
package org.wildfly.plugin.tools.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author [email protected]
 * @author James R. Perkins
 */
public class Utils {
    private static final Pattern WHITESPACE_IF_NOT_QUOTED = Pattern.compile("(\\S+\"[^\"]+\")|\\S+");

    /**
     * Splits the arguments into a list. The arguments are split based on
     * whitespace while ignoring whitespace that is within quotes.
     *
     * @param arguments the arguments to split
     *
     * @return the list of the arguments
     */
    public static List splitArguments(final CharSequence arguments) {
        final List args = new ArrayList<>();
        final Matcher m = WHITESPACE_IF_NOT_QUOTED.matcher(arguments);
        while (m.find()) {
            final String value = m.group();
            if (!value.isBlank()) {
                args.add(value);
            }
        }
        return args;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy