mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
the double quotes " and the the backslash needs to be
escaped. Especially for characters like the command -data-evaluate-espression to work correctly.
This commit is contained in:
parent
5fec881d73
commit
1f82bf446b
1 changed files with 29 additions and 10 deletions
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.debug.mi.core.command;
|
package org.eclipse.cdt.debug.mi.core.command;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
|
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -94,18 +93,38 @@ public class MICommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
// According to the MI documentation '-' is not permitted
|
// We need to escape the double quotes and the backslash.
|
||||||
//(parameters[i].indexOf('-') != -1 || parameters[i].indexof(\n)
|
sb.setLength(0);
|
||||||
if (parameters[i].indexOf('\t') != -1 ||
|
String param = parameters[i];
|
||||||
parameters[i].indexOf('\"') != -1 ||
|
for (int j = 0; j < param.length(); j++) {
|
||||||
parameters[i].indexOf(' ') != -1) {
|
char c = param.charAt(j);
|
||||||
command += " \"" + parameters[i] + "\"";
|
if (c == '"' || c == '\\') {
|
||||||
} else {
|
sb.append('\\');
|
||||||
command += " " + parameters[i];
|
}
|
||||||
|
sb.append(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the string contains spaces instead of escaping
|
||||||
|
// surround the parameter with double quotes.
|
||||||
|
if (containsWhitespace(param)) {
|
||||||
|
sb.insert(0, '"');
|
||||||
|
sb.append('"');
|
||||||
|
}
|
||||||
|
command += " " + sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return command + "\n";
|
return command + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean containsWhitespace(String s) {
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
if (Character.isWhitespace(s.charAt(i))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue