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