< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptingFunctions.java

Print this page
rev 1297 : 8081604: rename ScriptingFunctions.tokenizeCommandLine

*** 135,145 **** public static Object exec(final Object self, final Object string, final Object input) throws IOException, InterruptedException { // Current global is need to fetch additional inputs and for additional results. final ScriptObject global = Context.getGlobal(); // Set up initial process. ! final ProcessBuilder processBuilder = new ProcessBuilder(tokenizeCommandLine(JSType.toString(string))); // Current ENV property state. final Object env = global.get(ENV_NAME); if (env instanceof ScriptObject) { final ScriptObject envProperties = (ScriptObject)env; --- 135,145 ---- public static Object exec(final Object self, final Object string, final Object input) throws IOException, InterruptedException { // Current global is need to fetch additional inputs and for additional results. final ScriptObject global = Context.getGlobal(); // Set up initial process. ! final ProcessBuilder processBuilder = new ProcessBuilder(tokenizeString(JSType.toString(string))); // Current ENV property state. final Object env = global.get(ENV_NAME); if (env instanceof ScriptObject) { final ScriptObject envProperties = (ScriptObject)env;
*** 235,261 **** private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { return MH.findStatic(MethodHandles.lookup(), ScriptingFunctions.class, name, MH.type(rtype, types)); } /** ! * Break an exec string into tokens, honoring quoted arguments and escaped ! * spaces. * ! * @param execString a {@link String} with the command line to execute. * @return a {@link List} of {@link String}s representing the tokens that ! * constitute the command line. * @throws IOException in case {@link StreamTokenizer#nextToken()} raises it. */ ! public static List<String> tokenizeCommandLine(final String execString) throws IOException { ! final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(execString)); tokenizer.resetSyntax(); tokenizer.wordChars(0, 255); tokenizer.whitespaceChars(0, ' '); tokenizer.commentChar('#'); tokenizer.quoteChar('"'); tokenizer.quoteChar('\''); ! final List<String> cmdList = new ArrayList<>(); final StringBuilder toAppend = new StringBuilder(); while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { final String s = tokenizer.sval; // The tokenizer understands about honoring quoted strings and recognizes // them as one token that possibly contains multiple space-separated words. --- 235,260 ---- private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { return MH.findStatic(MethodHandles.lookup(), ScriptingFunctions.class, name, MH.type(rtype, types)); } /** ! * Break a string into tokens, honoring quoted arguments and escaped spaces. * ! * @param str a {@link String} to tokenize. * @return a {@link List} of {@link String}s representing the tokens that ! * constitute the string. * @throws IOException in case {@link StreamTokenizer#nextToken()} raises it. */ ! public static List<String> tokenizeString(final String str) throws IOException { ! final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(str)); tokenizer.resetSyntax(); tokenizer.wordChars(0, 255); tokenizer.whitespaceChars(0, ' '); tokenizer.commentChar('#'); tokenizer.quoteChar('"'); tokenizer.quoteChar('\''); ! final List<String> tokenList = new ArrayList<>(); final StringBuilder toAppend = new StringBuilder(); while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { final String s = tokenizer.sval; // The tokenizer understands about honoring quoted strings and recognizes // them as one token that possibly contains multiple space-separated words.
*** 263,277 **** // escaping \ character. This is handled here. if (s.endsWith("\\")) { // omit trailing \, append space instead toAppend.append(s.substring(0, s.length() - 1)).append(' '); } else { ! cmdList.add(toAppend.append(s).toString()); toAppend.setLength(0); } } if (toAppend.length() != 0) { ! cmdList.add(toAppend.toString()); } ! return cmdList; } } --- 262,276 ---- // escaping \ character. This is handled here. if (s.endsWith("\\")) { // omit trailing \, append space instead toAppend.append(s.substring(0, s.length() - 1)).append(' '); } else { ! tokenList.add(toAppend.append(s).toString()); toAppend.setLength(0); } } if (toAppend.length() != 0) { ! tokenList.add(toAppend.toString()); } ! return tokenList; } }
< prev index next >