public String escapeQuotes ( final String toEscape ) { if ( toEscape . indexOf ( "\"" ) > - 1 && toEscape . indexOf ( "'" ) > - 1 ) { boolean quoteIsLast = false ; if ( toEscape . indexOf ( "\"" ) == toEscape . length ( ) - 1 ) { quoteIsLast = true ; } String [ ] substrings = toEscape . split ( "\"" ) ; StringBuilder quoted = new StringBuilder ( "concat(" ) ; for ( int i = 0 ; i < substrings . length ; i ++ ) { quoted . append ( "\"" ) . append ( substrings [ i ] ) . append ( "\"" ) ; quoted . append ( ( ( i == substrings . length - 1 ) ? ( quoteIsLast ? ", '\"')" : ")" ) : ", '\"', " ) ) ; } return quoted . toString ( ) ; } if ( toEscape . indexOf ( "\"" ) > - 1 ) { return String . format ( "'%s'" , toEscape ) ; } return String . format ( "\"%s\"" , toEscape ) ; }
Escapes the quotes for the supplied string .