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")); }
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 }
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()); }
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")); }
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')); }
/// <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()); }
internal override void Read(Tokeniser t, CharacterReader r) { string data = r.ConsumeTo("]]>"); t.Emit(data); r.MatchConsume("]]>"); t.Transition(TokeniserState.Data); }
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; } }
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); }