Table of Contents

BiffString Struct

Definition

Namespace
Bodu.IO.Biff
Assembly
Bodu.IO.Biff.dll
Package
Bodu.IO.Biff 1.0.0
Source
BiffString.cs

Provides a span-backed view over a text value embedded in a BIFF record - a BIFF8 Unicode string (16-bit or compressed 8-bit characters with option flags, rich-text runs, and extended data) or a BIFF5 code-page byte string - without materializing a string until the caller asks for one.

public readonly ref struct BiffString
Inherited Members

Remarks

BIFF8 stores text as UTF-16LE code units or, when every character has a zero high byte, as one low byte per character; a flags byte preceding the characters selects the form (IsHighByte) and announces the optional formatting-run and phonetic (extended) trailers. BIFF5 stores text as bytes in the code page declared by the stream's CODEPAGE record; the view carries that code page so GetString() needs no argument.

The view is a ref struct over the record payload and must not outlive the buffer it was read from.

Properties

CodePage

Gets the code page used to decode a byte string.

public int CodePage { get; }

Property Value

int

The Windows code page number; unused for a Unicode string.

EncodedLength

Gets the total number of bytes the string structure occupies in its record, including its length prefix, flags, and trailers.

public int EncodedLength { get; }

Property Value

int

The encoded size in bytes.

ExtendedData

Gets the extended (phonetic) data as raw bytes.

public ReadOnlySpan<byte> ExtendedData { get; }

Property Value

ReadOnlySpan<byte>

The extended data, or an empty span.

HasExtendedData

Gets a value indicating whether the string carries extended (phonetic) data.

public bool HasExtendedData { get; }

Property Value

bool

true when the header's extended-data flag is set.

HasRichRuns

Gets a value indicating whether the string carries rich-text formatting runs.

public bool HasRichRuns { get; }

Property Value

bool

true when the header's rich-text flag is set.

IsEmpty

Gets a value indicating whether the string holds no characters.

public bool IsEmpty { get; }

Property Value

bool

true when Length is zero.

IsHighByte

Gets a value indicating whether the characters are stored as 16-bit code units.

public bool IsHighByte { get; }

Property Value

bool

true when each character occupies two bytes; false for the compressed 8-bit form and for byte strings.

IsUnicode

Gets a value indicating whether the string is in the BIFF8 Unicode form.

public bool IsUnicode { get; }

Property Value

bool

true for a BIFF8 Unicode string; false for a BIFF5 code-page byte string.

Length

Gets the character count the string header declared.

public int Length { get; }

Property Value

int

For a Unicode string, the number of UTF-16 code units; for a byte string, the number of bytes, which equals the number of characters only for single-byte code pages.

RawCharacters

Gets the raw character bytes exactly as stored: UTF-16LE code units, compressed low bytes, or code-page bytes.

public ReadOnlySpan<byte> RawCharacters { get; }

Property Value

ReadOnlySpan<byte>

The character bytes.

RichRunCount

Gets the number of rich-text formatting runs.

public int RichRunCount { get; }

Property Value

int

The run count, or zero when the string is not rich text.

RichRuns

Gets the rich-text formatting runs as raw bytes: four bytes per run, a 16-bit character index followed by a 16-bit font index.

public ReadOnlySpan<byte> RichRuns { get; }

Property Value

ReadOnlySpan<byte>

The run bytes, or an empty span.

Methods

CopyTo(Span<char>)

Decodes the characters into the supplied destination.

public int CopyTo(Span<char> destination)

Parameters

destination Span<char>

The buffer that receives the decoded characters.

Returns

int

The number of characters written.

Exceptions

ArgumentException

Thrown when destination is shorter than GetCharCount().

BiffFormatException

Thrown when a byte string's code page cannot be resolved.

GetCharCount()

Gets the number of characters GetString() produces.

public int GetCharCount()

Returns

int

The decoded character count.

Exceptions

BiffFormatException

Thrown when a byte string's code page cannot be resolved.

GetString()

Decodes the characters into a new string.

public string GetString()

Returns

string

The decoded text.

Exceptions

BiffFormatException

Thrown when a byte string's code page cannot be resolved.

ToString()

Returns the decoded text.

public override string ToString()

Returns

string

The decoded text.

Applies to

ProductVersions
.NET8, 10