From 24c08a82eb98c5b17901752866b8e4dbe5ee46a8 Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 2 Dec 2010 20:33:30 +0000 Subject: 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 --- .../java/org/apache/tuscany/sca/shell/Shell.java | 45 +++++++++++++++++----- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'sca-java-2.x/trunk') 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 toksList = new ArrayList(); - for (String s : toks) { - if (s != null && s.trim().length() > 0) { - toksList.add(s); - } - } + List 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 getTokens(String[] toks) { List toksList = new ArrayList(); - for (String s : toks) { - if (s != null && s.trim().length() > 0) { - toksList.add(s); + for (int i=0; i 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 eval(final List toks) { final String op = toks.size() > 0 ? toks.get(0) : ""; -- cgit v1.2.3