Inheritance: ReadTags
 public void TestAttributesNoDelim()
 {
     const string html = "<img src=picture.gif alt=APicture>";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == 0);
     Tag tag = parse.LastTag;
     Assert.IsNotNull(tag);
     Assert.IsTrue(tag.Name.Equals("img"));
     Assert.IsTrue(tag.GetAttributeValue("src").Equals("picture.gif"));
     Assert.IsTrue(tag.GetAttributeValue("alt").Equals("APicture"));
 }
Example #2
0
        /// <summary>
        /// Perform a Yahoo search.
        /// </summary>
        /// <param name="url">The REST URL.</param>
        /// <returns>The search results.</returns>
        private ICollection<Uri> DoSearch(Uri url)
        {

            ICollection<Uri> result = new List<Uri>();
            // submit the search
            WebRequest http = HttpWebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)http.GetResponse();

            using (Stream istream = response.GetResponseStream())
            {
                ReadHTML parse = new ReadHTML(istream);
                StringBuilder buffer = new StringBuilder();
                bool capture = false;

                // parse the results
                int ch;
                while ((ch = parse.Read()) != -1)
                {
                    if (ch == 0)
                    {
                        Tag tag = parse.LastTag;
                        if (tag.Name.Equals("Url", StringComparison.CurrentCultureIgnoreCase))
                        {
                            buffer.Length = 0;
                            capture = true;
                        }
                        else if (tag.Name.Equals("/Url", StringComparison.CurrentCultureIgnoreCase))
                        {
                            result.Add(new Uri(buffer.ToString()));
                            buffer.Length = 0;
                            capture = false;
                        }
                    }
                    else
                    {
                        if (capture)
                        {
                            buffer.Append((char)ch);
                        }
                    }
                }
            }

            response.Close();

            return result;
        }
        public void TestAttributeLess()
        {
            const string html = "12<b>12</b>1";
            var enc = new ASCIIEncoding();
            var bis = new MemoryStream(enc.GetBytes(html));

            var parse = new ReadHTML(bis);
            Assert.IsTrue(parse.Read() == '1');
            Assert.IsTrue(parse.Read() == '2');
            Assert.IsTrue(parse.Read() == 0);
            Assert.IsTrue(parse.LastTag.Name.Equals("b"));
            Assert.IsTrue(parse.LastTag.TagType == Tag.Type.Begin);
            Assert.IsTrue(parse.Read() == '1');
            Assert.IsTrue(parse.Read() == '2');
            Assert.IsTrue(parse.Read() == 0);
            Tag tag = parse.LastTag;
            Assert.IsTrue(tag.Name.Equals("b"));
            Assert.IsTrue(tag.TagType == Tag.Type.End);
            Assert.AreEqual(tag.ToString(), "</b>");
            Assert.IsTrue(parse.Read() == '1');
        }
 public void TestBoth()
 {
     const string html = "<br/>";
     const string htmlName = "br";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == 0);
     Tag tag = parse.LastTag;
     Assert.IsNotNull(tag);
     Assert.IsTrue(tag.TagType == Tag.Type.Begin);
     Assert.IsTrue(tag.Name.Equals(htmlName));
     parse.ReadToTag();
     tag = parse.LastTag;
     Assert.IsNotNull(tag);
     Assert.IsTrue(tag.TagType == Tag.Type.End);
     Assert.IsTrue(tag.Name.Equals(htmlName));
 }
 public void TestToString()
 {
     const  string html = "a<img src=\"picture.gif\" alt=\"A Picture\">b";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     parse.ReadToTag();
     Assert.IsTrue(parse.ToString().IndexOf("A Picture") != -1);
 }
 public void TestTagToString()
 {
     const string html = "<br/>";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == 0);
 }
 public void TestSpecialCharacter()
 {
     const string html = "&lt;&gt;&#65;";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == '<');
     Assert.IsTrue(parse.Read() == '>');
     Assert.IsTrue(parse.Read() == 'A');
 }
 public void TestSimpleAttribute()
 {
     const string html = "<!DOCTYPE \"test\">";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == 0);
     Tag tag = parse.LastTag;
     Assert.AreEqual(tag.ToString(), html);
 }
 public void TestScript2()
 {
     const string html = "a<script>1<2</script>b<br>";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == 'a');
     Assert.IsTrue(parse.Read() == 0);
     Assert.IsTrue(parse.Read() == '1');
     Assert.IsTrue(parse.Read() == '<');
     Assert.IsTrue(parse.Read() == '2');
     Assert.IsTrue(parse.Read() == 0);
     Assert.IsTrue(parse.Read() == 'b');
     Assert.IsTrue(parse.Read() == 0);
 }
Example #10
0
 public void TestComment()
 {
     const string html = "a<!-- Hello -->b";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == 'a');
     Assert.IsTrue(parse.Read() == 0);
     Assert.IsTrue(parse.Read() == 'b');
 }
Example #11
0
 public void TestBothWithAttributes()
 {
     const string html = "<img src=\"picture.gif\" alt=\"A Picture\"/>";
     var enc = new ASCIIEncoding();
     var bis = new MemoryStream(enc.GetBytes(html));
     var parse = new ReadHTML(bis);
     Assert.IsTrue(parse.Read() == 0);
 }
Example #12
0
        /// <summary>
        /// Load the data units.  Once the lower level data units have been 
        /// loaded, the contents can be loaded.
        /// </summary>
        /// <param name="istream">The input stream that the data units are loaded from.</param>
        protected void LoadDataUnits(Stream istream)
        {
            var text = new StringBuilder();
            int ch;
            var parse = new ReadHTML(istream);
            bool style = false;
            bool script = false;

            while ((ch = parse.Read()) != -1)
            {
                if (ch == 0)
                {
                    if (style)
                    {
                        CreateCodeDataUnit(text.ToString());
                    }
                    else if (script)
                    {
                        CreateCodeDataUnit(text.ToString());
                    }
                    else
                    {
                        CreateTextDataUnit(text.ToString());
                    }
                    style = false;
                    script = false;

                    text.Length = 0;
                    CreateTagDataUnit(parse.LastTag);
                    if (String.Compare(parse.LastTag.Name, "style", true) == 0)
                    {
                        style = true;
                    }
                    else if (string.Compare(parse.LastTag.Name,
                                            "script", true) == 0)
                    {
                        script = true;
                    }
                }
                else
                {
                    text.Append((char) ch);
                }
            }

            CreateTextDataUnit(text.ToString());
        }
Example #13
0
 private ICollection<Uri> x7cdeaeac68d869b5(Uri xf50d6d3c10c0eac9)
 {
     ICollection<Uri> is2 = new List<Uri>();
     HttpWebResponse response = (HttpWebResponse) WebRequest.Create(xf50d6d3c10c0eac9).GetResponse();
     using (Stream stream = response.GetResponseStream())
     {
         StringBuilder builder;
         bool flag;
         int num;
         Tag lastTag;
         ReadHTML dhtml = new ReadHTML(stream);
         goto Label_014A;
     Label_002D:
         if (15 == 0)
         {
             goto Label_004F;
         }
     Label_0034:
         if ((num = dhtml.Read()) != -1)
         {
             goto Label_0159;
         }
         goto Label_006F;
     Label_0046:
         if (0x7fffffff == 0)
         {
             goto Label_0078;
         }
         goto Label_002D;
     Label_004F:
         if ((((uint) flag) - ((uint) flag)) > uint.MaxValue)
         {
             goto Label_0046;
         }
         if (0 == 0)
         {
         }
         goto Label_0034;
     Label_006F:
         if (4 != 0)
         {
             goto Label_0181;
         }
         goto Label_0046;
     Label_0078:
         if (lastTag.Name.Equals("/Url", StringComparison.CurrentCultureIgnoreCase))
         {
             goto Label_00F9;
         }
         if ((((uint) num) - ((uint) flag)) < 0)
         {
             goto Label_010B;
         }
         goto Label_0034;
     Label_00A9:
         if (!flag)
         {
             if ((((uint) flag) + ((uint) num)) >= 0)
             {
                 goto Label_004F;
             }
             goto Label_0046;
         }
         builder.Append((char) num);
         if (((uint) num) <= uint.MaxValue)
         {
             goto Label_0046;
         }
     Label_00EF:
         if (4 != 0)
         {
             goto Label_0078;
         }
     Label_00F9:
         is2.Add(new Uri(builder.ToString()));
     Label_010B:
         builder.Length = 0;
         flag = false;
         goto Label_0034;
     Label_011D:
         builder.Length = 0;
         flag = true;
         goto Label_0034;
     Label_012D:
         if (lastTag.Name.Equals("Url", StringComparison.CurrentCultureIgnoreCase))
         {
             goto Label_011D;
         }
         if (0 == 0)
         {
         }
         goto Label_00EF;
     Label_014A:
         builder = new StringBuilder();
         flag = false;
         goto Label_0034;
     Label_0159:
         if (num != 0)
         {
             goto Label_00A9;
         }
         lastTag = dhtml.LastTag;
         goto Label_012D;
     }
     Label_0181:
     response.Close();
     return is2;
 }
Example #14
0
 protected void LoadDataUnits(Stream istream)
 {
     int num;
     ReadHTML dhtml;
     bool flag;
     bool flag2;
     StringBuilder builder = new StringBuilder();
     if (-1 != 0)
     {
         dhtml = new ReadHTML(istream);
         flag = false;
         flag2 = false;
         goto Label_002C;
     }
     Label_0010:
     this.x82cd1c1497f0cbf7(builder.ToString());
     return;
     Label_002C:
     if ((num = dhtml.Read()) != -1)
     {
         if (num != 0)
         {
             builder.Append((char) num);
             goto Label_002C;
         }
         if (flag)
         {
             this.xcf6c4f40a62f8405(builder.ToString());
             goto Label_00F8;
         }
         if (0 != 0)
         {
             goto Label_00A1;
         }
         if (flag2)
         {
             this.xcf6c4f40a62f8405(builder.ToString());
             if (((uint) flag2) >= 0)
             {
                 goto Label_00F8;
             }
         }
         else
         {
             this.x82cd1c1497f0cbf7(builder.ToString());
         }
         if (0 == 0)
         {
             goto Label_00F8;
         }
     }
     else
     {
         goto Label_0010;
     }
     Label_0070:
     flag2 = true;
     if ((((uint) flag2) & 0) == 0)
     {
         if ((((uint) flag2) & 0) != 0)
         {
             goto Label_00F8;
         }
         if ((((uint) num) < 0) || (3 != 0))
         {
             goto Label_002C;
         }
         goto Label_0010;
     }
     if (((uint) flag) > uint.MaxValue)
     {
     }
     goto Label_00F8;
     Label_00A1:
     if (string.Compare(dhtml.LastTag.Name, "style", true) == 0)
     {
         flag = true;
         goto Label_002C;
     }
     if (string.Compare(dhtml.LastTag.Name, "script", true) != 0)
     {
         goto Label_002C;
     }
     goto Label_0070;
     Label_00F8:
     flag = false;
     flag2 = false;
     if (0 == 0)
     {
         builder.Length = 0;
         this.x83582e0ac008c5cb(dhtml.LastTag);
         goto Label_00A1;
     }
     goto Label_0070;
 }