Example usage for org.apache.commons.text StringTokenizer nextToken

List of usage examples for org.apache.commons.text StringTokenizer nextToken

Introduction

In this page you can find the example usage for org.apache.commons.text StringTokenizer nextToken.

Prototype

public String nextToken() 

Source Link

Document

Gets the next token from the String.

Usage

From source file:com.blackducksoftware.integration.hub.detect.detector.clang.ClangCompileCommandParser.java

public List<String> getCompilerArgsForGeneratingDepsMkFile(final String origCompileCommand,
        final String depsMkFilePath, final Map<String, String> optionOverrides) {
    logger.trace(String.format("origCompileCommand         : %s", origCompileCommand));
    String quotesRemovedCompileCommand = escapeQuotedWhitespace(origCompileCommand.trim());
    logger.trace(String.format("quotesRemovedCompileCommand: %s", quotesRemovedCompileCommand));
    StringTokenizer tokenizer = new StringTokenizer(quotesRemovedCompileCommand);
    tokenizer.setQuoteMatcher(StringMatcherFactory.INSTANCE.quoteMatcher());
    final List<String> argList = new ArrayList<>();
    String lastPart = "";
    int partIndex = 0;
    while (tokenizer.hasNext()) {
        String part = unEscapeDoubleQuotes(restoreWhitespace(tokenizer.nextToken()));
        if (partIndex > 0) {
            String optionValueOverride = null;
            for (String optionToOverride : optionOverrides.keySet()) {
                if (optionToOverride.equals(lastPart)) {
                    optionValueOverride = optionOverrides.get(optionToOverride);
                }//  w  ww  . jav  a 2  s .  c  o m
            }
            if (optionValueOverride != null) {
                argList.add(optionValueOverride);
            } else {
                argList.add(part);
            }
        }
        lastPart = part;
        partIndex++;
    }
    argList.add("-M");
    argList.add("-MF");
    argList.add(depsMkFilePath);
    return argList;
}