Beispiel #1
0
 public static bool IsDelimiter(char c, char delimiter)
 {
     if (delimiter == '"')
     {
         return(SpecialCharacters.IsDoubleQuote(c));
     }
     return(delimiter == '\'' ? SpecialCharacters.IsSingleQuote(c) : (int)c == (int)delimiter);
 }
Beispiel #2
0
 public static char AsQuote(char c)
 {
     if (SpecialCharacters.IsSingleQuote(c))
     {
         return('\'');
     }
     return(SpecialCharacters.IsDoubleQuote(c) ? '"' : c);
 }
Beispiel #3
0
        /// <summary>
        /// Escapes content so that it is safe for inclusion in a single-quoted string.
        /// For example: "'" + EscapeSingleQuotedStringContent(userContent) + "'"
        /// </summary>
        /// <param name="value">The content to be included in a single-quoted string.</param>
        /// <returns>Content with all single-quotes escaped.</returns>
        public static string EscapeSingleQuotedStringContent(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }
            StringBuilder sb = new StringBuilder(value.Length);

            foreach (char c in value)
            {
                sb.Append(c);
                if (SpecialCharacters.IsSingleQuote(c))
                {
                    // double-up quotes to escape them
                    sb.Append(c);
                }
            }
            return(sb.ToString());
        }
Beispiel #4
0
 public static bool IsQuote(char c) => SpecialCharacters.IsSingleQuote(c) | SpecialCharacters.IsDoubleQuote(c);