Exemple #1
0
        /// <summary>
        /// 将含有HTML实体字符的字符串解码
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <returns></returns>
        public static string DecodeHTMLString(string input, bool skipWiteSpace)
        {
            char          c;
            int           i  = 0;
            StringBuilder sb = new StringBuilder(input.Length);

            while (i < input.Length)
            {
                c = input[i];
                if (c == '&')
                {
                    i++;
                    int j = i;
                    while (j - i < _maxEntLen && j < input.Length)
                    {
                        if (input[j] == ';')
                        {
                            if (j - i > 0)
                            {
                                char e = DecodeEntity(new string(input.ToCharArray(i, j - i)));
                                if (e == HtmlConst.CHEMPTY)
                                {
                                    break;
                                }
                                sb.Append(e);
                            }
                            else
                            {
                                sb.Append("&;");
                            }
                            j++;
                            i = j;
                            break;
                        }
                        j++;
                    }
                    if (i != j)
                    {
                        sb.Append('&');
                    }
                    continue;
                }
                else
                {
                    if (skipWiteSpace)
                    {
                        if (!HtmlConst.IsWhiteSpace(c))
                        {
                            sb.Append(c);
                        }
                    }
                    else
                    {
                        sb.Append(c);
                    }
                }
                i++;
            }
            return(sb.ToString());
        }
Exemple #2
0
        /// <summary>
        /// 解析样式
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        public Dictionary <string, string> ParseStyleString(string style)
        {
            int    i = 0;
            char   c;
            string key;
            string val;
            int    valStartIndex = 0;
            int    keyStartIndex = -1;

            while (i < style.Length)
            {
                c = style[i];
                if (c == ':')
                {
                    if (keyStartIndex == -1)
                    {
                        i++;
                        continue;
                    }
                    //key = new string(style.ToCharArray(keyStartIndex, i - keyStartIndex));
                    key = this.GetStringToLower(style, keyStartIndex, i - keyStartIndex);
                    i++;
                    while (i < style.Length)
                    {
                        if (!HtmlConst.IsWhiteSpace(style[i]))
                        {
                            break;
                        }
                        i++;
                    }
                    int j = i;
                    valStartIndex = i;
                    while (j < style.Length)
                    {
                        if (style[j] == ';')
                        {
                            if (j - i > 0)
                            {
                                //val = new string(style.ToCharArray(i, j - i));
                                val = this.GetStringToLower(style, i, j - i);
                                Insert(key, val);
                            }
                            valStartIndex = 0;
                            keyStartIndex = -1;
                            i             = j;
                            break;
                        }
                        j++;
                    }
                    if (valStartIndex > 0)
                    {
                        if (j - i > 0)
                        {
                            //val = new string(style.ToCharArray(i, j - i));
                            val = this.GetStringToLower(style, i, j - i);
                            Insert(key, val);
                        }
                        valStartIndex = 0;
                        keyStartIndex = -1;
                        i             = j;
                        break;
                    }
                }
                else
                if (keyStartIndex == -1 && valStartIndex == 0)
                {
                    if (!HtmlConst.IsWhiteSpace(c))
                    {
                        keyStartIndex = i;
                    }
                }
                i++;
            }
            return(this._dic);
        }