public static String unquote ( String str ) throws Exception { int len = str . length ( ) ; StringBuffer buf = new StringBuffer ( len ) ; boolean inQuotes = false ; char c ; int i = 0 ; if ( str . charAt ( i ) == ' ' ) { inQuotes = true ; i ++ ; } while ( i < len ) { c = str . charAt ( i ) ; if ( inQuotes ) { if ( c == ' ' ) { inQuotes = false ; } else if ( c == ' ' ) { buf . append ( str . charAt ( ++ i ) ) ; } else { buf . append ( c ) ; } } else { if ( c == ' ' ) { if ( str . charAt ( i ++ ) != ' ' ) { throw new Exception ( "Malformed string." ) ; } } else if ( c == ' ' ) { inQuotes = true ; i ++ ; } else { buf . append ( c ) ; } } i ++ ; } return buf . toString ( ) ; }
Dequotifies a specified string . The quotes are removed and each \ is replaced with and each \\ is replaced with \ .