StringParser { static List<String> parse(String str) { List<String> strings = new ArrayList<>(); StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(str)); tokenizer.resetSyntax(); tokenizer.wordChars('a', 'z'); tokenizer.wordChars('A', 'Z'); tokenizer.wordChars('-', '-'); tokenizer.wordChars('0', '9'); tokenizer.wordChars('.', '.'); tokenizer.wordChars('~', '~'); tokenizer.wordChars(128 + 32, 255); tokenizer.whitespaceChars(' ', ' '); tokenizer.whitespaceChars(',', ','); tokenizer.quoteChar('"'); try { while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { strings.add(tokenizer.sval); } } catch (IOException e) { } return strings; } private  StringParser();   }
@Test public void parse() { String str = "a~1 1 abc, def, \"gh i\", \"jk,l\", \"m,n\\\" o\" a \" 'b \" 1.2 -3 \"quo\\\"ted\""; List<String> expected = ImmutableList.of("a~1", "1", "abc", "def", "gh i", "jk,l", "m,n\" o", "a", " 'b ", "1.2", "-3", "quo\"ted"); List<String> parsed = StringParser.parse(str); assertEquals(expected, parsed); }