/// <summary> /// Performs backslash processing on the specified value using a given /// method. /// </summary> /// <param name="value">The <see cref="string" /> to process.</param> /// <param name="processingMethod">The <see cref="BackslashProcessingMethod" /> to use.</param> /// <returns> /// <paramref name="value" /> with backslashes processed using the given /// <see cref="BackslashProcessingMethod" />. /// </returns> public static string ProcessTrailingBackslash(string value, BackslashProcessingMethod processingMethod) { string processedValue = null; switch (processingMethod) { case BackslashProcessingMethod.None: processedValue = value; break; case BackslashProcessingMethod.Duplicate: processedValue = DuplicateTrailingBackslash(value); break; case BackslashProcessingMethod.Fix: processedValue = FixTrailingBackslash(value); break; case BackslashProcessingMethod.Clean: processedValue = CleanTrailingBackslash(value); break; default: throw new InvalidEnumArgumentException("processingMethod", (int)processingMethod, typeof(BackslashProcessingMethod)); } return(processedValue); }
/// <summary> /// Quotes an argument value and processes backslashes using a given /// <see cref="BackslashProcessingMethod" />. /// </summary> /// <param name="value">The argument value to quote.</param> /// <param name="processingMethod">The <see cref="BackslashProcessingMethod" /> to use.</param> /// <returns> /// The quoted argument value. /// </returns> public static string QuoteArgumentValue(string value, BackslashProcessingMethod processingMethod) { // duplicate trailing backslashes (even if value is quoted) string quotedValue = ArgumentUtils.ProcessTrailingBackslash(value, processingMethod); // determine if value is already quoted bool isQuoted = value.StartsWith("\"") && value.EndsWith("\""); if (!isQuoted) { quotedValue = "\"" + quotedValue + "\""; } return(quotedValue); }
/// <summary> /// Performs backslash processing on the specified value using a given /// method. /// </summary> /// <param name="value">The <see cref="string" /> to process.</param> /// <param name="processingMethod">The <see cref="BackslashProcessingMethod" /> to use.</param> /// <returns> /// <paramref name="value" /> with backslashes processed using the given /// <see cref="BackslashProcessingMethod" />. /// </returns> public static string ProcessTrailingBackslash(string value, BackslashProcessingMethod processingMethod) { string processedValue = null; switch (processingMethod) { case BackslashProcessingMethod.None: processedValue = value; break; case BackslashProcessingMethod.Duplicate: processedValue = DuplicateTrailingBackslash(value); break; case BackslashProcessingMethod.Fix: processedValue = FixTrailingBackslash(value); break; case BackslashProcessingMethod.Clean: processedValue = CleanTrailingBackslash(value); break; default: throw new InvalidEnumArgumentException("processingMethod", (int) processingMethod, typeof(BackslashProcessingMethod)); } return processedValue; }
/// <summary> /// Quotes an argument value and processes backslashes using a given /// <see cref="BackslashProcessingMethod" />. /// </summary> /// <param name="value">The argument value to quote.</param> /// <param name="processingMethod">The <see cref="BackslashProcessingMethod" /> to use.</param> /// <returns> /// The quoted argument value. /// </returns> public static string QuoteArgumentValue(string value, BackslashProcessingMethod processingMethod) { // duplicate trailing backslashes (even if value is quoted) string quotedValue = ArgumentUtils.ProcessTrailingBackslash(value, processingMethod); // determine if value is already quoted bool isQuoted = value.StartsWith("\"") && value.EndsWith("\""); if (!isQuoted) { quotedValue = "\"" + quotedValue + "\""; } return quotedValue; }