mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Break the toString() method is two smaller methods.
This commit is contained in:
parent
f4b76e52e0
commit
c96dfdc80c
1 changed files with 36 additions and 18 deletions
|
@ -6,14 +6,11 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.debug.mi.core.command;
|
package org.eclipse.cdt.debug.mi.core.command;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Represents a MI command.
|
* Represents a MI command.
|
||||||
*/
|
*/
|
||||||
public class MICommand extends Command
|
public class MICommand extends Command {
|
||||||
{
|
|
||||||
final String[] empty = new String[0];
|
final String[] empty = new String[0];
|
||||||
String[] options = empty;
|
String[] options = empty;
|
||||||
String[] parameters = empty;
|
String[] parameters = empty;
|
||||||
|
@ -71,24 +68,31 @@ public class MICommand extends Command
|
||||||
parameters = p;
|
parameters = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
protected String optionsToString() {
|
||||||
String command = getToken() + getOperation();
|
StringBuffer sb = new StringBuffer();
|
||||||
if (options != null && options.length > 0) {
|
if (options != null && options.length > 0) {
|
||||||
for (int i = 0; i < options.length; i++) {
|
for (int i = 0; i < options.length; i++) {
|
||||||
if (options[i].indexOf('\t') != -1 ||
|
// If the option contains a space according to
|
||||||
options[i].indexOf(' ') != -1) {
|
// GDB/MI spec we must surround it with double quotes.
|
||||||
command += " \"" + options[i] + "\"";
|
if (options[i].indexOf('\t') != -1 || options[i].indexOf(' ') != -1) {
|
||||||
|
sb.append(' ').append('"').append(options[i]).append('"');
|
||||||
} else {
|
} else {
|
||||||
command += " " + options[i];
|
sb.append(' ').append(options[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return sb.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String parametersToString() {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
if (parameters != null && parameters.length > 0) {
|
if (parameters != null && parameters.length > 0) {
|
||||||
// Add a "--" separator if a parameter starts with "-"
|
// According to GDB/MI spec
|
||||||
|
// Add a "--" separator if any parameters start with "-"
|
||||||
if (options != null && options.length > 0) {
|
if (options != null && options.length > 0) {
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
if (parameters[i].startsWith("-")) {
|
if (parameters[i].startsWith("-")) {
|
||||||
command += " --";
|
buffer.append('-').append('-');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,10 +117,24 @@ public class MICommand extends Command
|
||||||
sb.insert(0, '"');
|
sb.insert(0, '"');
|
||||||
sb.append('"');
|
sb.append('"');
|
||||||
}
|
}
|
||||||
command += " " + sb.toString();
|
buffer.append(' ').append(sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return command + "\n";
|
return buffer.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuffer command = new StringBuffer(getToken() + getOperation());
|
||||||
|
String opt = optionsToString();
|
||||||
|
if (opt.length() > 0) {
|
||||||
|
command.append(' ').append(opt);
|
||||||
|
}
|
||||||
|
String p = parametersToString();
|
||||||
|
if (p.length() > 0) {
|
||||||
|
command.append(' ').append(p);
|
||||||
|
}
|
||||||
|
command.append('\n');
|
||||||
|
return command.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean containsWhitespace(String s) {
|
boolean containsWhitespace(String s) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue