@Test public void testTokenizeQuotedStrings() { String[] tokens; tokens = StringUtils.tokenizeQuotedStrings( "hello world", " " ); assertArrayEquals( new String[] { "hello", "world" }, tokens ); tokens = StringUtils.tokenizeQuotedStrings( "\"hello world\"", " " ); assertArrayEquals( new String[] { "hello world" }, tokens ); tokens = StringUtils.tokenizeQuotedStrings( "\"hello world\", \"foo\", 'bar'", ", " ); assertArrayEquals( new String[] { "hello world", "foo", "'bar'" }, tokens ); tokens = StringUtils.tokenizeQuotedStrings( "\"hello, world\", \"foo bar\", 'bar'", ", " ); assertArrayEquals( new String[] { "hello, world", "foo bar", "'bar'" }, tokens ); tokens = StringUtils.tokenizeQuotedStrings( "\"hello world of darkness\", \"foo bar\", 'bar'", ", " ); assertArrayEquals( new String[] { "hello world of darkness", "foo bar", "'bar'" }, tokens ); tokens = StringUtils.tokenizeQuotedStrings( "\"hello , darkness\", \"foo \t bar\", 'bar'", ", " ); assertArrayEquals( new String[] { "hello , darkness", "foo \t bar", "'bar'" }, tokens ); }
public static String[] tokenizeQuotedStrings( final String aInput, final String aDelimiters ) { if ( aInput == null ) { return null; } final List<String> result = new ArrayList<String>(); String lookback = ""; boolean inQuotedString = false; final StringTokenizer tokenizer = new StringTokenizer( aInput, aDelimiters, true ); while ( tokenizer.hasMoreTokens() ) { String token = tokenizer.nextToken(); if ( !inQuotedString && token.startsWith( "\"" ) && !token.endsWith( "\"" ) ) { inQuotedString = true; lookback = token; } else if ( inQuotedString ) { lookback = lookback.concat( token ); if ( token.endsWith( "\"" ) ) { inQuotedString = false; token = lookback; } } if ( !inQuotedString && !isDelimiter( token, aDelimiters ) ) { result.add( token ); } } final ListIterator<String> iter = result.listIterator(); while ( iter.hasNext() ) { final String token = iter.next(); iter.set( unquote( token ) ); } return result.toArray( new String[result.size()] ); }
StringUtils { public static String[] tokenizeQuotedStrings( final String aInput, final String aDelimiters ) { if ( aInput == null ) { return null; } final List<String> result = new ArrayList<String>(); String lookback = ""; boolean inQuotedString = false; final StringTokenizer tokenizer = new StringTokenizer( aInput, aDelimiters, true ); while ( tokenizer.hasMoreTokens() ) { String token = tokenizer.nextToken(); if ( !inQuotedString && token.startsWith( "\"" ) && !token.endsWith( "\"" ) ) { inQuotedString = true; lookback = token; } else if ( inQuotedString ) { lookback = lookback.concat( token ); if ( token.endsWith( "\"" ) ) { inQuotedString = false; token = lookback; } } if ( !inQuotedString && !isDelimiter( token, aDelimiters ) ) { result.add( token ); } } final ListIterator<String> iter = result.listIterator(); while ( iter.hasNext() ) { final String token = iter.next(); iter.set( unquote( token ) ); } return result.toArray( new String[result.size()] ); } }
StringUtils { public static String[] tokenizeQuotedStrings( final String aInput, final String aDelimiters ) { if ( aInput == null ) { return null; } final List<String> result = new ArrayList<String>(); String lookback = ""; boolean inQuotedString = false; final StringTokenizer tokenizer = new StringTokenizer( aInput, aDelimiters, true ); while ( tokenizer.hasMoreTokens() ) { String token = tokenizer.nextToken(); if ( !inQuotedString && token.startsWith( "\"" ) && !token.endsWith( "\"" ) ) { inQuotedString = true; lookback = token; } else if ( inQuotedString ) { lookback = lookback.concat( token ); if ( token.endsWith( "\"" ) ) { inQuotedString = false; token = lookback; } } if ( !inQuotedString && !isDelimiter( token, aDelimiters ) ) { result.add( token ); } } final ListIterator<String> iter = result.listIterator(); while ( iter.hasNext() ) { final String token = iter.next(); iter.set( unquote( token ) ); } return result.toArray( new String[result.size()] ); } private  StringUtils(); }
StringUtils { public static String[] tokenizeQuotedStrings( final String aInput, final String aDelimiters ) { if ( aInput == null ) { return null; } final List<String> result = new ArrayList<String>(); String lookback = ""; boolean inQuotedString = false; final StringTokenizer tokenizer = new StringTokenizer( aInput, aDelimiters, true ); while ( tokenizer.hasMoreTokens() ) { String token = tokenizer.nextToken(); if ( !inQuotedString && token.startsWith( "\"" ) && !token.endsWith( "\"" ) ) { inQuotedString = true; lookback = token; } else if ( inQuotedString ) { lookback = lookback.concat( token ); if ( token.endsWith( "\"" ) ) { inQuotedString = false; token = lookback; } } if ( !inQuotedString && !isDelimiter( token, aDelimiters ) ) { result.add( token ); } } final ListIterator<String> iter = result.listIterator(); while ( iter.hasNext() ) { final String token = iter.next(); iter.set( unquote( token ) ); } return result.toArray( new String[result.size()] ); } private  StringUtils(); static String integerToBinString( final int aValue, final int aFieldWidth ); static String integerToHexString( final int aValue, final int aFieldWidth ); static boolean isEmpty( final String aValue ); static String[] tokenize( final String aInput, final String aDelimiters ); static String[] tokenizeQuotedStrings( final String aInput, final String aDelimiters ); static String unquote( final String aInput ); static String unquote( final String aInput, final char aQuoteChar ); }
StringUtils { public static String[] tokenizeQuotedStrings( final String aInput, final String aDelimiters ) { if ( aInput == null ) { return null; } final List<String> result = new ArrayList<String>(); String lookback = ""; boolean inQuotedString = false; final StringTokenizer tokenizer = new StringTokenizer( aInput, aDelimiters, true ); while ( tokenizer.hasMoreTokens() ) { String token = tokenizer.nextToken(); if ( !inQuotedString && token.startsWith( "\"" ) && !token.endsWith( "\"" ) ) { inQuotedString = true; lookback = token; } else if ( inQuotedString ) { lookback = lookback.concat( token ); if ( token.endsWith( "\"" ) ) { inQuotedString = false; token = lookback; } } if ( !inQuotedString && !isDelimiter( token, aDelimiters ) ) { result.add( token ); } } final ListIterator<String> iter = result.listIterator(); while ( iter.hasNext() ) { final String token = iter.next(); iter.set( unquote( token ) ); } return result.toArray( new String[result.size()] ); } private  StringUtils(); static String integerToBinString( final int aValue, final int aFieldWidth ); static String integerToHexString( final int aValue, final int aFieldWidth ); static boolean isEmpty( final String aValue ); static String[] tokenize( final String aInput, final String aDelimiters ); static String[] tokenizeQuotedStrings( final String aInput, final String aDelimiters ); static String unquote( final String aInput ); static String unquote( final String aInput, final char aQuoteChar );  }