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