public void TextHelpers_Decode1() { // Try parsing a simple unicode char and escaped char string text = @"u\52 \l(foo.jpg)"; CharacterStream cs = new CharacterStream(new StringTextProvider(text)); Assert.IsFalse(TextHelpers.AtEscape(cs)); Assert.IsFalse(TextHelpers.AtUnicodeEscape(cs)); Assert.AreEqual(new DecodedChar('u', 1), TextHelpers.DecodeCurrentChar(cs)); Assert.IsTrue(cs.Advance(1)); Assert.IsTrue(TextHelpers.AtEscape(cs)); Assert.IsTrue(TextHelpers.AtUnicodeEscape(cs)); Assert.AreEqual('R', TextHelpers.DecodeCurrentChar(cs).Char); Assert.AreEqual(4, TextHelpers.DecodeCurrentChar(cs).EncodedLength); Assert.IsTrue(cs.Advance(4)); Assert.IsTrue(TextHelpers.AtEscape(cs)); Assert.IsFalse(TextHelpers.AtUnicodeEscape(cs)); Assert.AreEqual('l', TextHelpers.DecodeCurrentChar(cs).Char); Assert.AreEqual(2, TextHelpers.DecodeCurrentChar(cs).EncodedLength); Assert.IsTrue(cs.Advance(2)); Assert.IsFalse(TextHelpers.AtEscape(cs)); Assert.IsFalse(TextHelpers.AtUnicodeEscape(cs)); Assert.AreEqual(new DecodedChar('(', 1), TextHelpers.DecodeCurrentChar(cs)); Assert.AreEqual(@"uRl(foo.jpg)", TextHelpers.DecodeText(cs.TextProvider, 0, text.Length, forStringToken: false)); }
public void TextHelpers_Decode2() { // Try parsing a unicode char that's larger than 0xFFFF CharacterStream cs = new CharacterStream(new StringTextProvider(@"\abcd1234")); Assert.IsTrue(TextHelpers.AtEscape(cs)); Assert.IsTrue(TextHelpers.AtUnicodeEscape(cs)); DecodedChar dc = TextHelpers.DecodeCurrentChar(cs); Assert.AreEqual(7, dc.EncodedLength); Assert.IsTrue(dc.RequiresUtf32); Assert.AreEqual(0xABCD12, dc.CharUtf32); Assert.AreEqual('\0', dc.Char); Assert.IsTrue(cs.Advance(dc.EncodedLength)); Assert.AreEqual('3', cs.CurrentChar); }
protected bool AtEscape() { return(TextHelpers.AtEscape(CS)); }