@@ -34,7 +34,7 @@ public static String[] formatAndSplit(String src, Map<String, String> dict,
34
34
String res ;
35
35
36
36
// Recursive replace with a max depth of 10 levels.
37
- for (int i = 0 ; i < 10 ; i ++) {
37
+ for (int i = 0 ; i < 10 ; i ++) {
38
38
// Do a replace with dictionary
39
39
res = StringReplacer .replaceFromMapping (src , dict );
40
40
if (!recursive )
@@ -45,42 +45,43 @@ public static String[] formatAndSplit(String src, Map<String, String> dict,
45
45
}
46
46
47
47
// Split the resulting string in arguments
48
- return quotedSplit (src , '"' , false );
48
+ return quotedSplit (src , " \" '" , false );
49
49
}
50
50
51
- public static String [] quotedSplit (String src , char escapeChar ,
51
+ public static String [] quotedSplit (String src , String quoteChars ,
52
52
boolean acceptEmptyArguments )
53
53
throws Exception {
54
- String quote = "" + escapeChar ;
55
54
List <String > res = new ArrayList <String >();
56
55
String escapedArg = null ;
57
- boolean escaping = false ;
56
+ String escapingChar = null ;
58
57
for (String i : src .split (" " )) {
59
- if (!escaping ) {
60
- if (!i .startsWith (quote )) {
58
+ if (escapingChar == null ) {
59
+ // If the first char is not an escape char..
60
+ String first = i .substring (0 , 1 );
61
+ if (!quoteChars .contains (first )) {
61
62
if (i .trim ().length () != 0 || acceptEmptyArguments )
62
63
res .add (i );
63
64
continue ;
64
65
}
65
66
66
- escaping = true ;
67
+ escapingChar = first ;
67
68
i = i .substring (1 );
68
69
escapedArg = "" ;
69
70
}
70
71
71
- if (!i .endsWith (quote )) {
72
+ if (!i .endsWith (escapingChar )) {
72
73
escapedArg += i + " " ;
73
74
continue ;
74
75
}
75
76
76
77
escapedArg += i .substring (0 , i .length () - 1 );
77
78
if (escapedArg .trim ().length () != 0 || acceptEmptyArguments )
78
79
res .add (escapedArg );
79
- escaping = false ;
80
+ escapingChar = null ;
80
81
}
81
- if (escaping )
82
- throw new Exception ("Invalid quoting: no closing ' " + escapeChar +
83
- "' char found." );
82
+ if (escapingChar != null )
83
+ throw new Exception ("Invalid quoting: no closing [ " + escapingChar +
84
+ "] char found." );
84
85
return res .toArray (new String [0 ]);
85
86
}
86
87
0 commit comments