예제 #1
0
        internal static string EscapeFormatString(string message, char[] permitted)
        {
            if (message == null)
            {
                return(string.Empty);
            }
            StringBuilder stringBuilder = new StringBuilder(message.Length);

            for (int i = 0; i < message.Length; i++)
            {
                char chr = message[i];
                stringBuilder.Append(chr);
                if (chr == '%' && i + 1 < message.Length)
                {
                    char chr1 = message[i + 1];
                    if (chr1 == '%' || UnixMarshal.IsCharPresent(permitted, chr1))
                    {
                        stringBuilder.Append(chr1);
                    }
                    else
                    {
                        stringBuilder.Append('%').Append(chr1);
                    }
                    i++;
                }
                else if (chr == '%')
                {
                    stringBuilder.Append('%');
                }
            }
            return(stringBuilder.ToString());
        }