Utf8TomlReader Struct
- Obsolete: Types with embedded references are not supported in this version of your compiler.
A high-performance, forward-only reader of TOML documents encoded in UTF-8.
[Obsolete("Types with embedded references are not supported in this version of your compiler.", true)]
public ref struct Utf8TomlReaderRemarks
The reader validates the syntax of the document (TOML 1.1, which accepts every TOML 1.0 document) and reads it one token at a time, without allocating. It does not check the rules that need the whole document, such as duplicate keys or tables defined twice: TomlDocument checks them.
A dotted key is read as one Utf8TomlTokenType.PropertyName token per segment. A table header is read as a Utf8TomlTokenType.TableHeader or Utf8TomlTokenType.ArrayOfTablesHeader token followed by the segments of its key. The last segment of a key has Utf8TomlTokenFlags.LastKeySegment.
Constructors
| Name | Description |
|---|---|
| Utf8TomlReader(ReadOnlySpan<byte>, Utf8TomlReaderOptions) | Initializes a new reader over a complete UTF-8 TOML document. |
| Utf8TomlReader(ReadOnlySpan<byte>, bool, Utf8TomlReaderState) | Initializes a new reader over a part of a UTF-8 TOML document. |
Utf8TomlReader overloads
Utf8TomlReader(ReadOnlySpan<byte>, Utf8TomlReaderOptions)
Utf8TomlReader.csInitializes a new reader over a complete UTF-8 TOML document.
public Utf8TomlReader(ReadOnlySpan<byte> utf8Toml, Utf8TomlReaderOptions options = default)Parameters
utf8TomlReadOnlySpan<byte>- The UTF-8 bytes of the document. A UTF-8 byte order mark at the start is skipped.
optionsUtf8TomlReaderOptions- The options of the reader.
Utf8TomlReader(ReadOnlySpan<byte>, bool, Utf8TomlReaderState)
Utf8TomlReader.csInitializes a new reader over a part of a UTF-8 TOML document.
public Utf8TomlReader(ReadOnlySpan<byte> utf8Toml, bool isFinalBlock, Utf8TomlReaderState state)Parameters
utf8TomlReadOnlySpan<byte>- The UTF-8 bytes to read.
isFinalBlockbooltruewhenutf8Tomlholds the end of the document.stateUtf8TomlReaderState- The state returned by
Utf8TomlReader.CurrentStateof the previous reader, or a new state for the first block.
Properties
| Name | Description |
|---|---|
| BufferOffset | Gets the offset in the whole document of the first byte of the input, when reading in several blocks. |
| BytesConsumed | Gets the number of bytes consumed: the input up to the end of the last token. |
| CurrentDepth | Gets the number of arrays and inline tables that contain the current token. |
| CurrentState | Gets the state to continue reading the document in a new reader. |
| IsFinalBlock | Gets a value indicating whether the input holds the end of the document. |
| IsLastKeySegment | Gets a value indicating whether the current key segment is the last one of its key. |
| LineNumber | Gets the 0-based line of the position reached by the reader. |
| Options | Gets the options of the reader. |
| TokenFlags | Gets how the last token is written. |
| TokenSpan | Gets the bytes of the last token, including the delimiters of a string or a quoted key. |
| TokenStartIndex | Gets the index in the input of the first byte of the last token. |
| TokenType | Gets the type of the last token read. |
| ValueIsEscaped | Gets a value indicating whether Utf8TomlReader.ValueSpan contains escape sequences that Utf8TomlReader.GetString decodes. |
| ValueSpan | Gets the bytes of the value of the last token: the content of a string or quoted key without its delimiters, the text of a number, a date or a boolean, or the text of a comment after its #. |
BufferOffset
Utf8TomlReader.csBytesConsumed
Utf8TomlReader.csCurrentDepth
Utf8TomlReader.csCurrentState
Utf8TomlReader.csGets the state to continue reading the document in a new reader.
public readonly Utf8TomlReaderState CurrentState { get; }Property value
IsFinalBlock
Utf8TomlReader.csIsLastKeySegment
Utf8TomlReader.csLineNumber
Utf8TomlReader.csOptions
Utf8TomlReader.csTokenFlags
Utf8TomlReader.csGets how the last token is written.
public readonly Utf8TomlTokenFlags TokenFlags { get; }Property value
TokenSpan
Utf8TomlReader.csGets the bytes of the last token, including the delimiters of a string or a quoted key.
public readonly ReadOnlySpan<byte> TokenSpan { get; }Property value
TokenStartIndex
Utf8TomlReader.csTokenType
Utf8TomlReader.csGets the type of the last token read.
public readonly Utf8TomlTokenType TokenType { get; }Property value
ValueIsEscaped
Utf8TomlReader.csGets a value indicating whether Utf8TomlReader.ValueSpan contains escape sequences that Utf8TomlReader.GetString decodes.
public readonly bool ValueIsEscaped { get; }Property value
ValueSpan
Utf8TomlReader.csGets the bytes of the value of the last token: the content of a string or quoted key without its delimiters, the text of a number, a date or a boolean, or the text of a comment after its #.
public readonly ReadOnlySpan<byte> ValueSpan { get; }Property value
Methods
| Name | Description |
|---|---|
| CopyString(Span<byte>) | Copies the decoded UTF-8 value of the current string, key segment or comment to utf8Destination. |
| CopyString(Span<char>) | Copies the decoded value of the current string, key segment or comment to destination. |
| GetBoolean() | Gets the value of the current boolean. |
| GetDouble() | Gets the value of the current float, or of the current integer converted to a Double. |
| GetInt64() | Gets the value of the current integer. |
| GetString() | Gets the decoded value of the current string, key segment or comment. |
| GetTomlDateTime() | Gets the value of the current date or time. |
| Read() | Reads the next token. |
| Skip() | Skips the children of the current token: the value of a key, or the content of an array or an inline table. |
| TryGetDateOnly(DateOnly) | Gets the value of the current local date. |
| TryGetDateTimeOffset(DateTimeOffset) | Gets the value of the current offset date-time, local date-time or local date as a DateTimeOffset. |
| TryGetDecimal(decimal) | Gets the value of the current number as a Decimal, parsed from its text to keep its digits. |
| TryGetDouble(double) | Gets the value of the current float, or of the current integer converted to a Double. |
| TryGetInt64(long) | Gets the value of the current integer. |
| TryGetTimeOnly(TimeOnly) | Gets the value of the current local time. |
| TryGetTomlDateTime(TomlDateTime) | Gets the value of the current date or time. |
| TrySkip() | Skips the children of the current token, when the input contains all of them. |
| ValueTextEquals(ReadOnlySpan<byte>) | Compares the decoded value of the current string or key segment to UTF-8 text, without allocating. |
| ValueTextEquals(ReadOnlySpan<char>) | Compares the decoded value of the current string or key segment to text, without allocating. |
| ValueTextEquals(string?) | Compares the decoded value of the current string or key segment to text, without allocating. |
CopyString overloads
CopyString(Span<byte>)
Utf8TomlReader.Values.csCopies the decoded UTF-8 value of the current string, key segment or comment to utf8Destination.
Parameters
utf8DestinationSpan<byte>
Returns
int The number of bytes written.
Remarks
The value is never longer than Utf8TomlReader.ValueSpan.
CopyString(Span<char>)
Utf8TomlReader.Values.csCopies the decoded value of the current string, key segment or comment to destination.
Parameters
destinationSpan<char>
Returns
int The number of characters written.
Remarks
The value has at most as many characters as Utf8TomlReader.ValueSpan has bytes.
GetBoolean()
Utf8TomlReader.Values.csGets the value of the current boolean.
public readonly bool GetBoolean()GetDouble()
Utf8TomlReader.Values.csGetInt64()
Utf8TomlReader.Values.csGets the value of the current integer.
public readonly long GetInt64()GetString()
Utf8TomlReader.Values.csGets the decoded value of the current string, key segment or comment.
public readonly string GetString()Returns
Exceptions
InvalidOperationException- The current token is not a string, a key segment or a comment.
GetTomlDateTime()
Utf8TomlReader.Values.csGets the value of the current date or time.
public readonly TomlDateTime GetTomlDateTime()Read()
Utf8TomlReader.csReads the next token.
public bool Read()Returns
bool true when a token was read; false at the end of the document, or when the input of a non-final block has no complete token left.
Exceptions
TomlException- The document is not valid TOML.
Skip()
Utf8TomlReader.csSkips the children of the current token: the value of a key, or the content of an array or an inline table.
public void Skip()Exceptions
InvalidOperationException- The input is not the final block. Use
Utf8TomlReader.TrySkip.
TryGetDateOnly(DateOnly)
Utf8TomlReader.Values.csTryGetDateTimeOffset(DateTimeOffset)
Utf8TomlReader.Values.csGets the value of the current offset date-time, local date-time or local date as a DateTimeOffset.
public readonly bool TryGetDateTimeOffset(out DateTimeOffset value)TryGetDecimal(decimal)
Utf8TomlReader.Values.csTryGetDouble(double)
Utf8TomlReader.Values.csTryGetInt64(long)
Utf8TomlReader.Values.csTryGetTimeOnly(TimeOnly)
Utf8TomlReader.Values.csTryGetTomlDateTime(TomlDateTime)
Utf8TomlReader.Values.csGets the value of the current date or time.
public readonly bool TryGetTomlDateTime(out TomlDateTime value)TrySkip()
Utf8TomlReader.csValueTextEquals overloads
ValueTextEquals(ReadOnlySpan<byte>)
Utf8TomlReader.Values.csCompares the decoded value of the current string or key segment to UTF-8 text, without allocating.
public readonly bool ValueTextEquals(ReadOnlySpan<byte> utf8Text)ValueTextEquals(ReadOnlySpan<char>)
Utf8TomlReader.Values.csCompares the decoded value of the current string or key segment to text, without allocating.
public readonly bool ValueTextEquals(ReadOnlySpan<char> text)