Beispiel #1
0
        /// <summary>
        /// Unscape all symbols for given type
        /// </summary>
        /// <param name="str"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static String Unescape(this String str, EscapingType type)
        {
            IEscapeProvider d   = EscapingDataFactory.Get(type);
            StringBuilder   res = new StringBuilder(str.Length);

            int offset = 0;

            foreach (var i in d.GetFirst())
            {
                if (str.StartsWith(i.Value))
                {
                    res.Append(i.Key);
                    offset = i.Value.Length;
                    break;
                }
            }

            for (int i = offset; i < str.Length; i++)
            {
                String s = CheckSuffix(str, offset, i, d);
                if (s != null)
                {
                    res.Append(s);
                    offset = i + 1;
                }
            }

            return(res + str.Substring(offset));
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="c"></param>
        /// <param name="type"></param>
        /// <param name="first"></param>
        /// <returns></returns>
        public static bool IsLiteral(this char c, EscapingType type, bool first = false)
        {
            IEscapeProvider d = EscapingDataFactory.Get(type);

            return(!(first && d.GetFirst().ContainsKey(c) ||
                     d.GetCommon().ContainsKey(c) ||
                     d.NeedEscapeUnicode(c)));
        }
Beispiel #3
0
        private static String EscapeFirst(char c, IEscapeProvider d)
        {
            String r;

            if (d.GetFirst().TryGetValue(c, out r))
            {
                return(r);
            }
            return(EscapeCommon(c, d));
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="str"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool IsLiteral(this String str, EscapingType type)
        {
            IEscapeProvider d = EscapingDataFactory.Get(type);

            if (d.GetFirst().ContainsKey(str[0]))
            {
                return(false);
            }
            foreach (char c in str)
            {
                if (d.GetCommon().ContainsKey(c))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #5
0
 private static String EscapeFirst(char c, IEscapeProvider d)
 {
     String r;
     if (d.GetFirst().TryGetValue(c, out r))
         return r;
     return EscapeCommon(c, d);
 }