needsQuoting() private static method

private static needsQuoting ( string s ) : bool
s string
return bool
Example #1
0
        public static string DoubleQuoteString(string value)
        {
            if (!MySqlHelper.needsQuoting(value))
            {
                return(value);
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < value.Length; i++)
            {
                char c = value[i];
                MySqlHelper.CharClass charClass = MySqlHelper.charClassArray[(int)c];
                if (charClass == MySqlHelper.CharClass.Quote)
                {
                    stringBuilder.Append(c);
                }
                else
                {
                    if (charClass == MySqlHelper.CharClass.Backslash)
                    {
                        stringBuilder.Append("\\");
                    }
                }
                stringBuilder.Append(c);
            }
            return(stringBuilder.ToString());
        }
Example #2
0
        public static string EscapeString(string value)
        {
            if (!MySqlHelper.needsQuoting(value))
            {
                return(value);
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < value.Length; i++)
            {
                char c = value[i];
                if (MySqlHelper.charClassArray[(int)c] != MySqlHelper.CharClass.None)
                {
                    stringBuilder.Append("\\");
                }
                stringBuilder.Append(c);
            }
            return(stringBuilder.ToString());
        }