Example #1
0
        public HtmlPage(Uri uri, byte[] htmlData, string httpHeadersCharset) : base(uri)
        {
            if (htmlData == null)
            {
                throw new ArgumentNullException("htmlData");
            }

            HeadersCharset = httpHeadersCharset;
            EncHeaders     = EncHelp.GetEncoding(HeadersCharset) ?? EncHelp.Windows1252;

            var prelimContent = EncHeaders.GetString(htmlData);

            DetermineEncoding(htmlData, prelimContent);
        }
Example #2
0
        void DetermineEncoding(byte[] contentData, string prelimContent)
        {
            HtmlCharset = EncHelp.GetCharset(prelimContent);
            EncHtml     = EncHelp.GetEncoding(HtmlCharset);

            // If they are in agreement or if the HTML doesn't have a charset declaration, use already forged string.
            if (EncHtml == EncHeaders || EncHtml == null)
            {
                UsedEncoding = EncHeaders;
                Content      = prelimContent;
            }
            // If they are not in agreement and the HTML has a charset declaration, reforge string.
            else
            {
                UsedEncoding = EncHtml;
                Content      = EncHtml.GetString(contentData);
            }
        }
Example #3
0
        public static WebString Create(WebBytes wb, Encoding fallbackEnc)
        {
            if (wb == null)
            {
                throw new ArgumentNullException("wb");
            }
            else if (fallbackEnc == null)
            {
                throw new ArgumentNullException("fallbackEnc");
            }

            if (wb.Success)
            {
                var enc = EncHelp.GetEncoding(wb.CharacterSet) ?? fallbackEnc;
                return(new WebString(wb.Location, wb.Data, enc));
            }
            else
            {
                return(new WebString(wb));
            }
        }