Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::xml::XMLSourceStore Class Reference

Owns XML source bytes and mutable source anchors. More...

#include "donner/base/xml/XMLSourceStore.h"

Public Member Functions

 XMLSourceStore ()=default
 Construct an empty source store.
 XMLSourceStore (std::string source)
 Construct a source store with initial source bytes.
std::string_view source () const
 Return the current source bytes.
std::uint64_t sourceVersion () const
 Return the monotonically increasing source version.
std::optional< SourceAnchorIdcreateAnchor (std::size_t offset, SourceAnchorBias bias=SourceAnchorBias::Before)
 Create an anchor at offset.
std::optional< SourceAnchorSpancreateSpan (std::size_t start, std::size_t end, SourceAnchorBias startBias=SourceAnchorBias::Before, SourceAnchorBias endBias=SourceAnchorBias::After)
 Create a span from two anchors.
std::optional< std::size_t > resolveAnchor (SourceAnchorId id) const
 Resolve an anchor to its current byte offset.
std::optional< ResolvedSourceSpanresolveSpan (SourceAnchorSpan span) const
 Resolve a span to current byte offsets.
void invalidateAnchor (SourceAnchorId id)
 Invalidate an anchor explicitly.
std::optional< XMLSourceDeltareplace (std::size_t offset, std::size_t length, std::string_view replacement)
 Replace a byte range in the source.

Detailed Description

Owns XML source bytes and mutable source anchors.

XMLSourceStore is the first primitive needed for structured editing. It keeps source ranges stable across edits by storing anchor ids instead of long-lived absolute offsets. Public callers may still resolve anchors to absolute byte offsets for diagnostics, tests, and source display.

Constructor & Destructor Documentation

◆ XMLSourceStore()

donner::xml::XMLSourceStore::XMLSourceStore ( std::string source)
explicit

Construct a source store with initial source bytes.

Parameters
sourceInitial XML source text.

Member Function Documentation

◆ createAnchor()

std::optional< SourceAnchorId > donner::xml::XMLSourceStore::createAnchor ( std::size_t offset,
SourceAnchorBias bias = SourceAnchorBias::Before )
nodiscard

Create an anchor at offset.

Parameters
offsetCurrent source byte offset.
biasInsertion behavior when an edit inserts exactly at offset.
Returns
The new anchor id, or std::nullopt if offset is out of bounds or not a UTF-8 boundary.

◆ createSpan()

std::optional< SourceAnchorSpan > donner::xml::XMLSourceStore::createSpan ( std::size_t start,
std::size_t end,
SourceAnchorBias startBias = SourceAnchorBias::Before,
SourceAnchorBias endBias = SourceAnchorBias::After )
nodiscard

Create a span from two anchors.

Parameters
startInclusive current source byte offset.
endExclusive current source byte offset.
startBiasInsertion behavior when an edit inserts exactly at start.
endBiasInsertion behavior when an edit inserts exactly at end.
Returns
The new span, or std::nullopt if either offset is invalid.

◆ invalidateAnchor()

void donner::xml::XMLSourceStore::invalidateAnchor ( SourceAnchorId id)

Invalidate an anchor explicitly.

Parameters
idAnchor id to invalidate.

◆ replace()

std::optional< XMLSourceDelta > donner::xml::XMLSourceStore::replace ( std::size_t offset,
std::size_t length,
std::string_view replacement )
nodiscard

Replace a byte range in the source.

Anchors before the edit remain fixed, anchors after the edit move by the byte delta, boundary anchors honor their insertion bias, and anchors strictly inside the removed range are invalidated.

Parameters
offsetStart byte offset of the edit.
lengthNumber of bytes to remove.
replacementReplacement source bytes.
Returns
Edit delta, or std::nullopt if the range or replacement is invalid.

◆ resolveAnchor()

std::optional< std::size_t > donner::xml::XMLSourceStore::resolveAnchor ( SourceAnchorId id) const
nodiscard

Resolve an anchor to its current byte offset.

Parameters
idAnchor id to resolve.
Returns
Current offset, or std::nullopt if the anchor was invalidated.

◆ resolveSpan()

std::optional< ResolvedSourceSpan > donner::xml::XMLSourceStore::resolveSpan ( SourceAnchorSpan span) const
nodiscard

Resolve a span to current byte offsets.

Parameters
spanSpan to resolve.
Returns
Current span, or std::nullopt if either anchor was invalidated or inverted.

The documentation for this class was generated from the following file: