mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 16:55:38 +02:00
PR: 223695 - previous parser failed on many test and did not pass correctly empty strings
This commit is contained in:
parent
dfc64b1281
commit
e7b542359a
1 changed files with 8 additions and 95 deletions
|
@ -10,8 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.launch;
|
package org.eclipse.cdt.launch;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||||
|
import org.eclipse.cdt.utils.CommandLineUtil;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.variables.IStringVariableManager;
|
import org.eclipse.core.variables.IStringVariableManager;
|
||||||
import org.eclipse.core.variables.VariablesPlugin;
|
import org.eclipse.core.variables.VariablesPlugin;
|
||||||
|
@ -22,89 +22,6 @@ import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
*/
|
*/
|
||||||
public class LaunchUtils {
|
public class LaunchUtils {
|
||||||
|
|
||||||
private static class ArgumentParser {
|
|
||||||
|
|
||||||
private String fArgs;
|
|
||||||
|
|
||||||
private int fIndex = 0;
|
|
||||||
|
|
||||||
private int ch = -1;
|
|
||||||
|
|
||||||
public ArgumentParser( String args ) {
|
|
||||||
fArgs = args;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] parseArguments() {
|
|
||||||
ArrayList v = new ArrayList();
|
|
||||||
ch = getNext();
|
|
||||||
while( ch > 0 ) {
|
|
||||||
while( Character.isWhitespace( (char)ch ) )
|
|
||||||
ch = getNext();
|
|
||||||
if ( ch == '"' ) {
|
|
||||||
v.add( parseString() );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
v.add( parseToken() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String[] result = new String[v.size()];
|
|
||||||
v.toArray( result );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getNext() {
|
|
||||||
if ( fIndex < fArgs.length() )
|
|
||||||
return fArgs.charAt( fIndex++ );
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String parseString() {
|
|
||||||
StringBuffer buf = new StringBuffer();
|
|
||||||
ch = getNext();
|
|
||||||
while( ch > 0 && ch != '"' ) {
|
|
||||||
if ( ch == '\\' ) {
|
|
||||||
ch = getNext();
|
|
||||||
if ( ch != '"' ) { // Only escape double quotes
|
|
||||||
buf.append( '\\' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( ch > 0 ) {
|
|
||||||
buf.append( (char)ch );
|
|
||||||
ch = getNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ch = getNext();
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String parseToken() {
|
|
||||||
StringBuffer buf = new StringBuffer();
|
|
||||||
while( ch > 0 && !Character.isWhitespace( (char)ch ) ) {
|
|
||||||
if ( ch == '\\' ) {
|
|
||||||
ch = getNext();
|
|
||||||
if ( ch > 0 ) {
|
|
||||||
if ( ch != '"' ) { // Only escape double quotes
|
|
||||||
buf.append( '\\' );
|
|
||||||
}
|
|
||||||
buf.append( (char)ch );
|
|
||||||
ch = getNext();
|
|
||||||
}
|
|
||||||
else if ( ch == -1 ) { // Don't lose a trailing backslash
|
|
||||||
buf.append( '\\' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( ch == '"' ) {
|
|
||||||
buf.append( parseString() );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
buf.append( (char)ch );
|
|
||||||
ch = getNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For given launch configuration returns the program arguments as
|
* For given launch configuration returns the program arguments as
|
||||||
* an array of individual arguments.
|
* an array of individual arguments.
|
||||||
|
@ -132,10 +49,6 @@ public class LaunchUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] parseArguments(String args) {
|
private static String[] parseArguments(String args) {
|
||||||
if ( args == null )
|
return CommandLineUtil.argumentsToArray(args);
|
||||||
return new String[0];
|
|
||||||
ArgumentParser parser = new ArgumentParser( args );
|
|
||||||
String[] res = parser.parseArguments();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue