コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: ArgumentUtils.cs プロジェクト: RoastBoy/nant
        /// <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;
        }
コード例 #4
0
ファイル: ArgumentUtils.cs プロジェクト: RoastBoy/nant
        /// <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;
        }