Skip to main content
summaryrefslogtreecommitdiffstats
path: root/launch
diff options
context:
space:
mode:
authorAlena Laskavaia2008-11-04 18:44:21 +0000
committerAlena Laskavaia2008-11-04 18:44:21 +0000
commite7b542359a0be56eb279ac14e88c0d1b2b5a849b (patch)
tree4c04de61a83e56213372585603644cf6ff3d5569 /launch
parentdfc64b12819d670df0f96e11477405009e783804 (diff)
downloadorg.eclipse.cdt-e7b542359a0be56eb279ac14e88c0d1b2b5a849b.tar.gz
org.eclipse.cdt-e7b542359a0be56eb279ac14e88c0d1b2b5a849b.tar.xz
org.eclipse.cdt-e7b542359a0be56eb279ac14e88c0d1b2b5a849b.zip
PR: 223695 - previous parser failed on many test and did not pass correctly empty strings
Diffstat (limited to 'launch')
-rw-r--r--launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java103
1 files changed, 8 insertions, 95 deletions
diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java
index 163956e0ca0..149aec8bb4b 100644
--- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java
+++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java
@@ -8,116 +8,33 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-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.utils.CommandLineUtil;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
-
+
/**
* Utility methods.
*/
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
* an array of individual arguments.
*/
- public static String[] getProgramArgumentsArray( ILaunchConfiguration config ) throws CoreException {
- return parseArguments( getProgramArguments( config ) );
+ public static String[] getProgramArgumentsArray(ILaunchConfiguration config) throws CoreException {
+ return parseArguments(getProgramArguments(config));
}
/**
* Returns the program arguments as a String.
*/
public static String getProgramArguments(ILaunchConfiguration config) throws CoreException {
- String args = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
+ String args = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
if (args != null) {
args = getStringVariableManager().performStringSubstitution(args);
}
@@ -131,11 +48,7 @@ public class LaunchUtils {
return VariablesPlugin.getDefault().getStringVariableManager();
}
- private static String[] parseArguments( String args ) {
- if ( args == null )
- return new String[0];
- ArgumentParser parser = new ArgumentParser( args );
- String[] res = parser.parseArguments();
- return res;
+ private static String[] parseArguments(String args) {
+ return CommandLineUtil.argumentsToArray(args);
}
}

Back to the top