Esempio n. 1
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"));
        }
Esempio n. 2
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
        }
Esempio n. 3
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());
        }
Esempio n. 4
0
        public void NextIndexOfString()
        {
            string          @in = "One Two something Two Three Four";
            CharacterReader r   = new CharacterReader(@in);

            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"));
        }
Esempio n. 5
0
        public void NextIndexOfChar()
        {
            string          @in = "blah blah";
            CharacterReader r   = new CharacterReader(@in);

            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'));
        }
Esempio n. 6
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());
        }
Esempio n. 7
0
 internal override void Read(Tokeniser t, CharacterReader r)
 {
     string data = r.ConsumeTo("]]>");
     t.Emit(data);
     r.MatchConsume("]]>");
     t.Transition(TokeniserState.Data);
 }
Esempio n. 8
0
            internal override void Read(Tokeniser t, CharacterReader r)
            {
                switch (r.Current())
                {
                    case TokeniserState.nullChar:
                        t.Error(this);
                        r.Advance();
                        t.Emit(TokeniserState.replacementChar);
                        break;

                    case TokeniserState.eof:
                        t.Emit(new Token.EOF());
                        break;

                    default:
                        string data = r.ConsumeTo(TokeniserState.nullChar);
                        t.Emit(data);
                        break;
                }
            }
Esempio n. 9
0
 internal 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.bogus = true;
     comment.data.Append(r.ConsumeTo('>'));
     // todo: replace nullChar with replaceChar
     t.Emit(comment);
     t.AdvanceTransition(TokeniserState.Data);
 }