Beispiel #1
0
        /// <summary>
        /// Utility method to consume reader and unescape entities found within.
        /// </summary>
        /// <param name="inAttribute"></param>
        /// <returns>Unescaped string from reader</returns>
        public string UnescapeEntities(bool inAttribute)
        {
            StringBuilder builder = new StringBuilder();

            while (!_reader.IsEmpty())
            {
                builder.Append(_reader.ConsumeTo('&'));
                if (_reader.Matches('&'))
                {
                    _reader.Consume();
                    char?c = ConsumeCharacterReference(null, inAttribute);
                    if (c == null)
                    {
                        builder.Append('&');
                    }
                    else
                    {
                        builder.Append(c);
                    }
                }
            }
            return(builder.ToString());
        }
Beispiel #2
0
 public void consumeLetterSequence()
 {
     CharacterReader r = new CharacterReader("One &bar; qux");
     Assert.AreEqual("One", r.ConsumeLetterSequence());
     Assert.AreEqual(" &", r.ConsumeTo("bar;"));
     Assert.AreEqual("bar", r.ConsumeLetterSequence());
     Assert.AreEqual("; qux", r.ConsumeToEnd());
 }
Beispiel #3
0
 public void consumeToString()
 {
     CharacterReader r = new CharacterReader("One Two Two Four");
     Assert.AreEqual("One ", r.ConsumeTo("Two"));
     Assert.AreEqual('T', r.Consume());
     Assert.AreEqual("wo ", r.ConsumeTo("Two"));
     Assert.AreEqual('T', r.Consume());
     Assert.AreEqual("wo Four", r.ConsumeTo("Qux"));
 }
Beispiel #4
0
 public void consumeToChar()
 {
     CharacterReader r = new CharacterReader("One Two Three");
     Assert.AreEqual("One ", r.ConsumeTo('T'));
     Assert.AreEqual("", r.ConsumeTo('T')); // on Two
     Assert.AreEqual('T', r.Consume());
     Assert.AreEqual("wo ", r.ConsumeTo('T'));
     Assert.AreEqual('T', r.Consume());
     Assert.AreEqual("hree", r.ConsumeTo('T')); // consume to end
 }
Beispiel #5
0
        public void nextIndexOfString()
        {
            string input = "One Two something Two Three Four";
            CharacterReader r = new CharacterReader(input);

            Assert.AreEqual(-1, r.NextIndexOf("Foo"));
            Assert.AreEqual(4, r.NextIndexOf("Two"));
            Assert.AreEqual("One Two ", r.ConsumeTo("something"));
            Assert.AreEqual(10, r.NextIndexOf("Two"));
            Assert.AreEqual("something Two Three Four", r.ConsumeToEnd());
            Assert.AreEqual(-1, r.NextIndexOf("Two"));
        }
Beispiel #6
0
        public void nextIndexOfChar()
        {
            string input = "blah blah";
            CharacterReader r = new CharacterReader(input);

            Assert.AreEqual(-1, r.NextIndexOf('x'));
            Assert.AreEqual(3, r.NextIndexOf('h'));
            String pull = r.ConsumeTo('h');
            Assert.AreEqual("bla", pull);
            r.Consume();
            Assert.AreEqual(2, r.NextIndexOf('l'));
            Assert.AreEqual(" blah", r.ConsumeToEnd());
            Assert.AreEqual(-1, r.NextIndexOf('x'));
        }
Beispiel #7
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     string data = r.ConsumeTo("]]>");
     t.Emit(data);
     r.MatchConsume("]]>");
     t.Transition(Data);
 }
Beispiel #8
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     switch (r.Current())
     {
         case _nullChar:
             t.Error(this);
             r.Advance();
             t.Emit(_replacementChar);
             break;
         case _eof:
             t.Emit(new Token.EOF());
             break;
         default:
             string data = r.ConsumeTo(_nullChar);
             t.Emit(data);
             break;
     }
 }
Beispiel #9
0
 public override void Read(Tokeniser t, CharacterReader r)
 {
     // todo: handle bogus comment starting from eof. when does that trigger?
     // rewind to capture character that lead us here
     r.Unconsume();
     Token.Comment comment = new Token.Comment();
     comment.Data.Append(r.ConsumeTo('>'));
     // todo: replace nullChar with replaceChar
     t.Emit(comment);
     t.AdvanceTransition(Data);
 }