IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
EncodingSpanWriter.cs
Go to the documentation of this file.
1using System;
2using System.Text;
3
4namespace IKVM.CoreLib.Text
5{
6
12 {
13
14 readonly Encoding _encoding;
15 Span<byte> _span;
18
24 public EncodingSpanWriter(Encoding encoding, Span<byte> span)
25 {
26 _encoding = encoding ?? throw new ArgumentNullException(nameof(encoding));
27 _span = span;
28 }
29
33 public readonly int BytesWritten => _bytesWritten;
34
38 public readonly int CharsWritten => _charsWritten;
39
44 public void Write(string text)
45 {
46 var l = _encoding.GetBytes(text, _span);
47 _span = _span.Slice(l);
48 _bytesWritten += l;
49 _charsWritten += text.Length;
50 }
51
56 public void Write(scoped ReadOnlySpan<char> text)
57 {
58 var l = _encoding.GetBytes(text, _span);
59 _span = _span.Slice(l);
60 _bytesWritten += l;
61 _charsWritten += text.Length;
62 }
63
67 public void WriteLine()
68 {
69 Write(Environment.NewLine);
70 }
71
72 }
73
74}
Provides an interface to write text to a Span<byte>.
void Write(string text)
Writes the text to the span, advancing the current position.
readonly int CharsWritten
Gets the number of characters written.
readonly int BytesWritten
Gets the number of bytes written.
void Write(scoped ReadOnlySpan< char > text)
Writes the text to the span, advancing the current position.
void WriteLine()
Writes a line feed to the span.
EncodingSpanWriter(Encoding encoding, Span< byte > span)
Initializes a new instance.