ValueStringWriter
Namespace: SnowBank.Buffers.Text · struct
Implements: IDisposable, IBufferWriter<char>
Small buffer that keeps a list of chunks that are larger and larger
Constructors
ValueStringWriter
ValueStringWriter(int capacity)
Constructs a writer with a minimum initial capacity
Properties
Capacity
int Capacity { get; }
Returns the current capacity of the buffer
Item
char Item { get; }
Memory
Memory<char> Memory { get; }
Returns a span with all the items already written to this buffer
Segment
ArraySegment<char> Segment { get; }
Returns a span with all the items already written to this buffer
Span
Span<char> Span { get; }
Returns a span with all the items already written to this buffer
Methods
Advance
void Advance(int count)
Allocate
Span<char> Allocate(int size)
Allocates a fixed-size span, and advance the cursor
size— Size of the buffer to allocate
Returns: Span of size size
The cursor is advanced by
Clear
void Clear()
Clears the content of the buffer
The buffer count is reset to zero, but the current backing store remains the same
CopyTo
int CopyTo(Span<char> destination)
Copies the content of the buffer into a destination span
int CopyTo(StringBuilder destination)
Copies the content of the buffer into a destination span
void CopyTo(IBufferWriter<byte> destination)
Copies the content of the buffer into a destination writer
void CopyTo(Stream destination)
Copies the content of the buffer into a destination stream
CopyToAsync
Task CopyToAsync(Stream destination, CancellationToken ct)
Copies the content of the buffer into a destination stream
CopyToUtf8
int CopyToUtf8(Span<byte> destination)
Copies the content of the buffer as UTF-8 bytes into a destination buffer
Dispose
void Dispose()
GetEnumerator
Enumerator GetEnumerator()
Returns an enumerator that will return all the characters written so far
GetMemory
Memory<char> GetMemory(int sizeHint = 0)
GetSpan
Span<char> GetSpan(int sizeHint = 0)
ToString
string ToString()
Returns a String with a copy of the content in this instance
Calling this method will not release the buffer allocated by this instance.
Use ToStringAndDispose to dispose the buffer as well, or ToStringAndClear if you intend to reuse the buffer for the next operation.
ToStringAndClear
string ToStringAndClear()
Returns a String with a copy of the content in this instance, and clears the buffer so that it can be reused immediately
This is the equivalent to calling , followed by
ToStringAndDispose
string ToStringAndDispose()
Returns a String with a copy of the content in this instance, and returns the buffer to the pool
This is the equivalent to calling , followed by
ToUtf8Slice
Slice ToUtf8Slice(ArrayPool<byte> pool = null)
Returns a Slice with a copy of the content in this instance
pool— If non-null, pool used to allocate the b
ToUtf8SliceAndClear
Slice ToUtf8SliceAndClear(ArrayPool<byte> pool = null)
Returns a Slice with a copy of the content in this instance, and clears the buffer so that it can be reused immediately
pool— If non-null, pool used to allocate the b
This is the equivalent to calling ToUtf8SliceOwner, followed by Clear
ToUtf8SliceAndDispose
Slice ToUtf8SliceAndDispose(ArrayPool<byte> pool = null)
Returns a Slice with a copy of the content in this instance, and returns the buffer to the pool
pool— If non-null, pool used to allocate the buffer for the returned slice. Otherwise, the buffer will be allocated on the heap
This is the equivalent to calling ToUtf8Slice, followed by Dispose
ToUtf8SliceOwner
SliceOwner ToUtf8SliceOwner(ArrayPool<byte> pool = null)
Returns a SliceOwner with a copy of the content in this instance
pool— Pool used has the backing store for the SliceOwner (Sharedis not specified)
Returns: SliceOwner instance with a copy of the content allocated using pool. The value MUST be disposed at a later point; otherwise, the buffer will not be returned to the pool.Calling this method will not release the buffer allocated by this instance.Use ToUtf8SliceOwnerAndDispose to dispose the buffer as well, or ToUtf8SliceOwnerAndClear if you intend to reuse the buffer for the next operation.
ToUtf8SliceOwnerAndClear
SliceOwner ToUtf8SliceOwnerAndClear(ArrayPool<byte> pool = null)
Returns a SliceOwner with a copy of the content in this instance, and clears the buffer so that it can be reused immediately
pool— Pool used has the backing store for the SliceOwner (Sharedis not specified)
Returns: SliceOwner instance with a copy of the content allocated using pool. The value MUST be disposed at a later point; otherwise, the buffer will not be returned to the pool.Calling this method will not release the buffer allocated by this instance.This is the equivalent to calling ToUtf8SliceOwner, followed by Clear
ToUtf8SliceOwnerAndDispose
SliceOwner ToUtf8SliceOwnerAndDispose(ArrayPool<byte> pool = null)
Returns a SliceOwner with a copy of the content in this instance, and returns the buffer to the pool
pool— Pool used has the backing store for the SliceOwner (Sharedis not specified)
Returns: SliceOwner instance with a copy of the content allocated using pool. The value MUST be disposed at a later point; otherwise, the buffer will not be returned to the pool.Calling this method will not release the buffer allocated by this instance.This is the equivalent to calling ToUtf8SliceOwner, followed by Dispose
TryCopyTo
bool TryCopyTo(Span<char> destination, out int written)
Copies the content of the buffer into a destination span, if it is large enough
TryCopyToUtf8
bool TryCopyToUtf8(Span<byte> destination, out int written)
Copies the content of the buffer as UTF-8 bytes into a destination buffer, if it is large enough
Write
void Write(char item)
Appends a character at the end of the buffer
void Write(string items)
Appends a string at the end of the buffer
void Write(ReadOnlySpan<char> items)
Appends a span of characters at the end of the buffer
void Write(ReadOnlyMemory<char> items)
Appends a span of characters at the end of the buffer
void Write(bool value)
Writes a text representation of a boolean ("true" or "false")
void Write(sbyte value)
Writes the text representation of a 16-bit signed integer, using the Invariant culture
value— Value to write
void Write(byte value)
Writes the text representation of a 16-bit unsigned integer, using the Invariant culture
value— Value to write
void Write(short value)
Writes the text representation of a 16-bit signed integer, using the Invariant culture
value— Value to write
void Write(ushort value)
Writes the text representation of a 16-bit unsigned integer, using the Invariant culture
value— Value to write
void Write(int value)
Writes the text representation of a 32-bit signed integer, using the Invariant culture
value— Value to write
void Write(uint value)
Writes the text representation of a 32-bit unsigned integer, using the Invariant culture
value— Value to write
void Write(long value)
Writes the text representation of a 64-bit signed integer, using the Invariant culture
value— Value to write
void Write(ulong value)
Writes the text representation of a 64-bit unsigned integer, using the Invariant culture
value— Value to write
void Write(Guid value)
Writes the text representation of a Guid, using the Invariant culture
value— Value to write
void Write(Uuid128 value)
Writes the text representation of a Uuid128, using the Invariant culture
value— Value to write
void Write(Uuid64 value)
Writes the text representation of a Uuid64, using the Invariant culture
value— Value to write
void Write(Int128 value)
Writes the text representation of a 64-bit signed integer, using the Invariant culture
value— Value to write
void Write(UInt128 value)
Writes the text representation of a 64-bit unsigned integer, using the Invariant culture
value— Value to write
void Write(float value)
Writes the text representation of a 32-bit IEEE floating point number, using the Invariant culture
value— Value to write
void Write(double value)
Writes the text representation of a 64-bit IEEE floating point number, using the Invariant culture
value— Value to write
void Write(decimal value)
Writes the text representation of a 128-bit decimal floating point number, using the Invariant culture
value— Value to write
void Write(Half value)
Writes the text representation of a 16-bit IEEE floating point number, using the Invariant culture
value— Value to write
void Write(char prefix, char value)
Appends two characters at the end of the buffer
void Write(char prefix, string value)
Appends a prefix character and a string at the end of the buffer
void Write(char prefix, ReadOnlySpan<char> value)
Appends a prefix character and a span of characters at the end of the buffer
void Write(ReadOnlySpan<char> prefix, ReadOnlySpan<char> value)
Appends two strings at the end of the buffer
void Write(char c, int count)
Writes a repeated character at the end of the buffer
void Write(char prefix, char value, char suffix)
Appends three characters at the end of the buffer
void Write(char prefix, string value, char suffix)
Appends a string surrounded with a prefix and suffix at the end of the buffer
void Write(char prefix, ReadOnlySpan<char> value, char suffix)
Appends a string surrounded with a prefix and suffix at the end of the buffer
void Write(char prefix, string value, string suffix)
Appends a character and two strings at the end of the buffer
void Write(ReadOnlySpan<char> prefix, ReadOnlySpan<char> value, ReadOnlySpan<char> suffix)
Appends three strings at the end of the buffer
void Write(ReadOnlySpan<char> prefix, ReadOnlySpan<char> value, char suffix)
Appends two strings and a suffix character at the end of the buffer
Fields
Count
int Count
Number of items in the buffer