@Test public final void testSplitIgnoreInQuotes() { Collection<String> split = Strings.splitIgnoreWithinQuotes("tritra tru lala", ' '); assertEquals(3, split.size()); Iterator<String> it = split.iterator(); assertEquals("tritra", it.next()); assertEquals("tru", it.next()); assertEquals("lala", it.next()); split = Strings.splitIgnoreWithinQuotes(" tri\"tra tru \" lala", ' '); it = split.iterator(); assertEquals(2, split.size()); assertEquals("tri\"tra tru \"", it.next()); assertEquals("lala", it.next()); split = Strings.splitIgnoreWithinQuotes("aa,\"bb,bb\",cc\",dd\"ee", ','); it = split.iterator(); assertEquals(3, split.size()); assertEquals("aa", it.next()); assertEquals("\"bb,bb\"", it.next()); assertEquals("cc\",dd\"ee", it.next()); split = Strings.splitIgnoreWithinQuotes( "xxx /tmp/demox\"Hello Dolly\"xthisxxxxisxxxx\" a test \"xxx", 'x'); it = split.iterator(); assertEquals(5, split.size()); assertEquals(" /tmp/demo", it.next()); assertEquals("\"Hello Dolly\"", it.next()); assertEquals("this", it.next()); assertEquals("is", it.next()); assertEquals("\" a test \"", it.next()); }
@Test public final void testSplitIgnoreInQuotesEmptyReturns() { Collection<String> split = Strings.splitIgnoreWithinQuotes("", ' '); assertEquals(0, split.size()); split = Strings.splitIgnoreWithinQuotes("x", 'x'); assertEquals(0, split.size()); split = Strings.splitIgnoreWithinQuotes(" ", ' '); assertEquals(0, split.size()); }
@Test public final void testSplitIgnoreInQuotesTrimmedRegexLiteral() { final Collection<String> split = Strings.splitIgnoreWithinQuotes( "|||This is a|| || |\"complicated||test.\"|||Hello, \"fox|and\"dog", '|'); final Iterator<String> it = split.iterator(); assertEquals(5, split.size()); assertEquals("This is a", it.next()); assertEquals(" ", it.next()); assertEquals(" ", it.next()); assertEquals("\"complicated||test.\"", it.next()); assertEquals("Hello, \"fox|and\"dog", it.next()); }