Escape character prepare for platform dependent...

This commit is contained in:
Emmanuel Bigeon 2016-06-12 12:15:11 -04:00
parent 12326b7cba
commit 4ddce780e0

View File

@ -51,11 +51,19 @@ import fr.bigeon.gclc.exception.CommandParsingException;
* @author Emmanuel Bigeon */
public class GCLCConstants {
/** The escaping character */
private static final char ESCAPING_CHAR = getSystemEscapingChar();
/** Hide utility class constructor */
private GCLCConstants() {
// utility class
}
/** @return the escaping character */
private static char getSystemEscapingChar() {
return '\\';
}
/** Splits a command in the diferrent arguments
*
* @param cmd the command to split in its parts
@ -71,7 +79,7 @@ public class GCLCConstants {
while (index < cmd.length()) {
char c = cmd.charAt(index);
index++;
if (escaped || c == '\\') {
if (escaped || c == ESCAPING_CHAR) {
escaped = !escaped;
continue;
}
@ -102,11 +110,11 @@ public class GCLCConstants {
private static String removeEscaped(String arg) {
StringBuilder builder = new StringBuilder();
int index = 0;
int endIndex = arg.indexOf('\\');
int endIndex = arg.indexOf(ESCAPING_CHAR);
while (endIndex != -1) {
builder.append(arg.subSequence(index, endIndex));
index = endIndex + 1;
endIndex = arg.indexOf('\\', index + 1);
endIndex = arg.indexOf(ESCAPING_CHAR, index + 1);
}
builder.append(arg.substring(index));
return builder.toString();