/** * <p>Quote and escape a String with the given character, handling <code>null</code>.</p> * <p/> * <pre> * StringUtils.quoteAndEscape(null, *) = null * StringUtils.quoteAndEscape("", *) = "" * StringUtils.quoteAndEscape("abc", '"') = abc * StringUtils.quoteAndEscape("a\"bc", '"') = "a\"bc" * StringUtils.quoteAndEscape("a\"bc", '\'') = 'a\"bc' * </pre> * * @param source The source. * @param quoteChar The quote character. * @return the String quoted and escaped * @see #quoteAndEscape(String, char, char[], char[], char, boolean) * @see #quoteAndEscape(String, char, char[], char[], char, boolean) * */ public static String quoteAndEscape( @Nullable String source, char quoteChar ) { return quoteAndEscape( source, quoteChar, new char[]{ quoteChar }, new char[]{ ' ' }, '\\', false ); }
/** * <p>Quote and escape a String with the given character, handling <code>null</code>.</p> * * @param source The source. * @param quoteChar The quote character. * @param quotingTriggers The quoting trigger. * @return the String quoted and escaped * @see #quoteAndEscape(String, char, char[], char[], char, boolean) * */ public static String quoteAndEscape( @Nullable String source, char quoteChar, @Nonnull char[] quotingTriggers ) { return quoteAndEscape( source, quoteChar, new char[]{ quoteChar }, quotingTriggers, '\\', false ); }
/** * @param source The source. * @param quoteChar The quote character. * @param escapedChars The escaped characters. * @param escapeChar The escape character. * @param force true/false. * @return the String quoted and escaped * @see #quoteAndEscape(String, char, char[], char[], char, boolean) * */ public static String quoteAndEscape( @Nullable String source, char quoteChar, @Nonnull final char[] escapedChars, char escapeChar, boolean force ) { return quoteAndEscape( source, quoteChar, escapedChars, new char[]{ ' ' }, escapeChar, force ); }
/** * @param line The line * @return The concatenate lines. */ public static String toString( String... line ) { // empty path return empty string if ( ( line == null ) || ( line.length == 0 ) ) { return ""; } // path containing one or more elements final StringBuilder result = new StringBuilder(); for ( int i = 0; i < line.length; i++ ) { if ( i > 0 ) { result.append( ' ' ); } try { result.append( StringUtils.quoteAndEscape( line[i], '\"' ) ); } catch ( Exception e ) { System.err.println( "Error quoting argument: " + e.getMessage() ); } } return result.toString(); }
return StringUtils.quoteAndEscape( path, '\"', BASH_QUOTING_TRIGGER_CHARS );
getEscapeChars( isSingleQuotedExecutableEscaped(), isDoubleQuotedExecutableEscaped() ); sb.append( StringUtils.quoteAndEscape( getExecutable(), getExecutableQuoteDelimiter(), escapeChars, getQuotingTriggerChars(), '\\', false ) ); sb.append( StringUtils.quoteAndEscape( argument, getArgumentQuoteDelimiter(), escapeChars, getQuotingTriggerChars(), '\\', false ) );