|
|
Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
|
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< SourceAnchorId > | createAnchor (std::size_t offset, SourceAnchorBias bias=SourceAnchorBias::Before) |
Create an anchor at offset. | |
| std::optional< SourceAnchorSpan > | createSpan (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< ResolvedSourceSpan > | resolveSpan (SourceAnchorSpan span) const |
| Resolve a span to current byte offsets. | |
| void | invalidateAnchor (SourceAnchorId id) |
| Invalidate an anchor explicitly. | |
| std::optional< XMLSourceDelta > | replace (std::size_t offset, std::size_t length, std::string_view replacement) |
| Replace a byte range in the source. | |
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.
|
explicit |
Construct a source store with initial source bytes.
| source | Initial XML source text. |
|
nodiscard |
Create an anchor at offset.
| offset | Current source byte offset. |
| bias | Insertion behavior when an edit inserts exactly at offset. |
offset is out of bounds or not a UTF-8 boundary.
|
nodiscard |
Create a span from two anchors.
| start | Inclusive current source byte offset. |
| end | Exclusive current source byte offset. |
| startBias | Insertion behavior when an edit inserts exactly at start. |
| endBias | Insertion behavior when an edit inserts exactly at end. |
| void donner::xml::XMLSourceStore::invalidateAnchor | ( | SourceAnchorId | id | ) |
Invalidate an anchor explicitly.
| id | Anchor id to invalidate. |
|
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.
| offset | Start byte offset of the edit. |
| length | Number of bytes to remove. |
| replacement | Replacement source bytes. |
|
nodiscard |
Resolve an anchor to its current byte offset.
| id | Anchor id to resolve. |
|
nodiscard |
Resolve a span to current byte offsets.
| span | Span to resolve. |