Udger.Parser.PerlRegExpConverter.EscapeBracketExpressionSpecialChars C# (CSharp) Method

EscapeBracketExpressionSpecialChars() static private method

Escapes characters that have special meaning in bracket expression to make them ordinary characters.
static private EscapeBracketExpressionSpecialChars ( string chars ) : string
chars string String possibly containing characters with special meaning.
return string
        internal static string EscapeBracketExpressionSpecialChars(string chars)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < chars.Length; i++)
            {
                char ch = chars[i];
                switch (ch)
                {
                    // case '^': // not necessary, not at the beginning have no special meaning
                    case '\\':
                    case ']':
                    case '-':
                        sb.Append('\\');
                        goto default;
                    default:
                        sb.Append(ch);
                        break;
                }
            }

            return sb.ToString();
        }