public static void AppendChar(this IWriter writer, char value) { int encodedBytes; var success = Utf8Encoder.TryEncodeCodePoint( new UnicodeCodePoint(value), writer.GetFreeBuffer(MaxUtf8CodePointBytes).ToSpan(), out encodedBytes); Debug.Assert(success); writer.CommitBytes(encodedBytes); }
public static void AppendString(this IWriter writer, string value) { var enumerator = new Utf16LittleEndianCodePointEnumerator(value); // no need to dispose this while (enumerator.MoveNext()) { int encodedBytes; var success = Utf8Encoder.TryEncodeCodePoint( enumerator.Current, writer.GetFreeBuffer(MaxUtf8CodePointBytes).ToSpan(), out encodedBytes); Debug.Assert(success); writer.CommitBytes(encodedBytes); } }
private static void AppendStringInternal(this IWriter writer, string value, int startIndex, int endIndex) { for (var i = startIndex; i <= endIndex;) { UnicodeCodePoint codePoint; int encodedChars; var success = Utf16LittleEndianEncoder.TryDecodeCodePointFromString(value, i, out codePoint, out encodedChars); if (!success) { throw new ArgumentException(); } i += encodedChars; int encodedBytes; success = Utf8Encoder.TryEncodeCodePoint( codePoint, writer.GetFreeBuffer(MaxUtf8CodePointBytes).ToSpan(), out encodedBytes); Debug.Assert(success); writer.CommitBytes(encodedBytes); } }