public void TestFromLatinCharacter() { ushort lead, trail; Assert.AreEqual(1, Utf16.FromCode(0x7a, out lead, out trail)); Assert.AreEqual(0x7a, lead); Assert.AreEqual(0, trail); Assert.AreEqual("\u007A", Utf16.FromCode(0x7A)); }
public void TestHighSingleComponent() { ushort lead, trail; Assert.AreEqual(1, Utf16.FromCode(0x6c34, out lead, out trail)); Assert.AreEqual(0x6c34, lead); Assert.AreEqual(0, trail); Assert.AreEqual("\u6C34", Utf16.FromCode(0x6C34)); }
public void TestNonBasic() { ushort lead, trail; Assert.AreEqual(2, Utf16.FromCode(0x1D11E, out lead, out trail)); Assert.AreEqual(0xD834, lead); Assert.AreEqual(0xDD1E, trail); Assert.AreEqual("\uD834\uDD1E", Utf16.FromCode(0x1D11E)); }
/// <summary> /// Reads plain text from the input stream. /// </summary> public static Span ReadSpan(InputBuffer buffer) { var span = new StringBuilder(); while (true) { var text = buffer.ConsumeUntil(b => _escapeChars.Contains(b)); span.Append(Encoding.UTF8.GetString(text, 0, text.Length)); byte?next; if (buffer.At(0) == '\\' && (next = buffer.At(1)).HasValue) { ControlWord word; int consumed; if (ParseControlWord(buffer, 0, out word, out consumed)) { if (word.Text == "u" && word.Parameter.HasValue && word.Parameter > 0) { // Handle unicode characters. span.Append(Utf16.FromCode((uint)word.Parameter)); buffer.Discard(consumed + 1); } else { break; } } else if (!IsAsciiLetter(next)) { // Handle control symbols. // TODO: Translate control symbol to special character, e.g. \~ => nbsp. span.Append((char)next.Value); buffer.Discard(2); } else { break; } } else { break; } } return(new Span(span.ToString())); }