diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-02 20:33:30 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-02 20:33:30 +0000 |
commit | 24c08a82eb98c5b17901752866b8e4dbe5ee46a8 (patch) | |
tree | 9e3f54748cbcded1e31d08b9e94477c862a8498e /sca-java-2.x/trunk | |
parent | 6bf99eb5eba8927df4e06ca26d106b3ba4074f69 (diff) |
Update to support entering quoted strings conatining spaces
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1041571 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java index 1174506613..0c06af891d 100644 --- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java +++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java @@ -319,12 +319,7 @@ public class Shell { while ((l = r.readLine()) != null) {
out.println(l);
String[] toks = l != null ? l.trim().split(" ") : "".split(" ");
- List<String> toksList = new ArrayList<String>();
- for (String s : toks) {
- if (s != null && s.trim().length() > 0) {
- toksList.add(s);
- }
- }
+ List<String> toksList = getTokens(toks);
apply(eval(toksList));
}
} finally {
@@ -488,15 +483,47 @@ public class Shell { l = ((BufferedReader)r).readLine();
history.add(l);
}
+
String[] toks = l != null ? l.trim().split(" ") : "bye".split(" ");
+ return getTokens(toks);
+ }
+
+ /**
+ * Parse the string into tokens, which may include quoted strings
+ */
+ List<String> getTokens(String[] toks) {
List<String> toksList = new ArrayList<String>();
- for (String s : toks) {
- if (s != null && s.trim().length() > 0) {
- toksList.add(s);
+ for (int i=0; i<toks.length; i++) {
+ if (toks[i] != null && toks[i].trim().length() > 0) {
+ int j = quotedString(toks, i);
+ if (j > -1) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(toks[i]);
+ for (int k=i+1; k<=j; k++) {
+ sb.append(" ");
+ sb.append(toks[k]);
+ }
+ i = j;
+ String s = sb.toString();
+ toksList.add(s.substring(1, s.length()-1));
+ } else {
+ toksList.add(toks[i]);
+ }
}
}
return toksList;
}
+
+ int quotedString(String[] toks, int i) {
+ if (toks[i].startsWith("\"") || toks[i].startsWith("'")) {
+ for (int j=i+1; j<toks.length; j++) {
+ if (toks[j].endsWith(toks[i].substring(0,0))) {
+ return j;
+ }
+ }
+ }
+ return -1;
+ }
Callable<Boolean> eval(final List<String> toks) {
final String op = toks.size() > 0 ? toks.get(0) : "";
|