Table of Contents

Class CharChainOperation

Namespace
Gve.Text
Assembly
Gve.Text.dll

Base class for operations on a Chain<T>.

public abstract class CharChainOperation : OperationMetadata
Inheritance
CharChainOperation
Derived
Inherited Members

Constructors

CharChainOperation(OperationType)

Initializes a new instance of the CharChainOperation class.

protected CharChainOperation(OperationType type)

Parameters

type OperationType

The operation type.

Properties

At

Gets or sets the ordinal character number to start at.

public int At { get; set; }

Property Value

int

AtAsIndex

Gets or sets a value indicating whether At refers to an index rather than a chain node ID.

public bool AtAsIndex { get; set; }

Property Value

bool

InputTag

Gets or sets the input version tag for this operation. If null, the default tag (=the tag of the last operation executed on the context) is used.

public string? InputTag { get; set; }

Property Value

string

OutputTag

Gets or sets the output version tag for this operation. If null, a value will be automatically generated from the input tag if this ends with digits; else, it will be equal to the input tag.

public string? OutputTag { get; set; }

Property Value

string

Run

Gets or sets the run of characters to include from At.

public int Run { get; set; }

Property Value

int

Type

Gets or sets the operation type.

public OperationType Type { get; protected set; }

Property Value

OperationType

Value

Gets the value argument for this operation. This is the primary argument, whose meaning varies depending on the operation type.

public string? Value { get; set; }

Property Value

string

Methods

AppendHead(StringBuilder)

Appends the head part of an operation to the specified string builder. The head is ATxRUN (optionally preceded by @) followed by OP.

protected void AppendHead(StringBuilder sb)

Parameters

sb StringBuilder

The target.

AppendTail(StringBuilder)

Appends the tail part of an operation to the specified string builder.

protected void AppendTail(StringBuilder sb)

Parameters

sb StringBuilder

The target.

Execute(ChainOperationContext<char>)

Executes this operation on the specified context.

public abstract void Execute(ChainOperationContext<char> context)

Parameters

context ChainOperationContext<char>

The context.

FindNode(Chain<char>, int, bool, string?)

Finds the node having its ID or index equal to at.

protected static ChainNode<char>? FindNode(Chain<char> chain, int at, bool atAsIndex = false, string? tag = null)

Parameters

chain Chain<char>

The chain.

at int

The value of node ID or index.

atAsIndex bool

if set to true, at represents an index rather than an ID.

tag string

The tag defining the context for the index. This can be null when at refers to an ID, which is not dependent on version tags.

Returns

ChainNode<char>

Node, or null if not found.

GetNextTag(string, ChainOperationContext<char>)

Gets the output tag from the input tag. This is the input tag with a version number incremented by 1, when it ends with digits; else, it is the input tag unless empty; when empty, the next tag is v0. If the calculated tag is lower than or equal to the maximum tag number in the context, it is set to the maximum tag number + 1. This ensures that we don't overwrite existing versions.

protected static string GetNextTag(string tag, ChainOperationContext<char> context)

Parameters

tag string

The tag.

context ChainOperationContext<char>

The context.

Returns

string

Tag.

Exceptions

ArgumentNullException

tag

GetNodesFrom(string)

Gets a new set of nodes representing text.

protected static List<ChainNode<char>> GetNodesFrom(string text)

Parameters

text string

The text.

Returns

List<ChainNode<char>>

Nodes.

GetOperationType(string)

Gets the operation type from the specified symbol.

protected static OperationType GetOperationType(string op)

Parameters

op string

Operator symbol.

Returns

OperationType

Type.

Exceptions

FormatException

Invalid operation type.

GetReferenceNodes(Chain<char>, string, int, int)

Gets the nodes referenced by this operation in relation with the specified chain and tag.

protected IList<ChainNode<char>> GetReferenceNodes(Chain<char> chain, string tag, int at = -1, int run = -1)

Parameters

chain Chain<char>

The target chain.

tag string

The version tag.

at int

The optional value of node ID or index. If -1, the value of At will be used.

run int

The optional run of characters to include from at. If -1, the value of Run will be used.

Returns

IList<ChainNode<char>>

Target node(s).

Exceptions

ArgumentNullException

chain or tag

InvalidOperationException

Node not found

GetTags(ChainOperationContext<char>)

Gets the input and output tags for this operation with relation to the received context.

public (string inputTag, string outputTag) GetTags(ChainOperationContext<char> context)

Parameters

context ChainOperationContext<char>

The context.

Returns

(string inputTag, string outputTag)

Input and output tags.

Exceptions

ArgumentNullException

context

LocOpRegex()

[GeneratedRegex("^(?:\\([^)]*\\))?\\s*@?[0-9x×]+(=|-|\\+\\[|\\+\\]|>\\[|>\\]|<>|:)")]
protected static Regex LocOpRegex()

Returns

Regex

Remarks

Pattern:

^(?:\([^)]\))?\s@?[0-9x×]+(=|-|\+\[|\+\]|>\[|>\]|<>|:)

Explanation:
○ Match if at the beginning of the string.
○ Optional (greedy).
○ Match '('.
○ Match a character other than ')' atomically any number of times.
○ Match ')'.
○ Match a whitespace character atomically any number of times.
○ Match '@' atomically, optionally.
○ Match a character in the set [0-9x\u00D7] atomically at least once.
○ 1st capture group.
○ Match with 7 alternative expressions, atomically.
○ Match a character in the set [-=].
○ Match the string "+[".
○ Match the string "+]".
○ Match the string ">[".
○ Match the string ">]".
○ Match the string "<>".
○ Match ':'.

ParseHeadAndTail(string, CharChainOperation)

Parse head and tail parts of the specified text representing an operation, storing values into operation.

protected static string ParseHeadAndTail(string text, CharChainOperation operation)

Parameters

text string

Text.

operation CharChainOperation

Target operation.

Returns

string

The body part of the text.

Exceptions

FormatException

Invalid text.

Parse<O>(string)

Parses the specified text representing an operation.

public static O Parse<O>(string text) where O : CharChainOperation

Parameters

text string

The text.

Returns

O

Operation.

Type Parameters

O

Exceptions

ArgumentNullException

text

FormatException

Parsing error

ToRegex()

[GeneratedRegex("^(?<tox>@)?(?<to>[0-9]+)")]
protected static Regex ToRegex()

Returns

Regex

Remarks

Pattern:

^(?<tox>@)?(?<to>[0-9]+)

Explanation:
○ Match if at the beginning of the string.
○ Optional (greedy).
○ "tox" capture group.
○ Match '@'.
○ "to" capture group.
○ Match a character in the set [0-9] atomically at least once.

ToRunRegex()

[GeneratedRegex("^(?<tox>@)?(?<to>[0-9]+)(?:[×x](?<torun>[0-9]+))?")]
protected static Regex ToRunRegex()

Returns

Regex

Remarks

Pattern:

^(?<tox>@)?(?<to>[0-9]+)(?:×x)?

Explanation:
○ Match if at the beginning of the string.
○ Optional (greedy).
○ "tox" capture group.
○ Match '@'.
○ "to" capture group.
○ Match a character in the set [0-9] greedily at least once.
○ Optional (greedy).
○ Match a character in the set [x\u00D7].
○ "torun" capture group.
○ Match a character in the set [0-9] atomically at least once.

ToString()

Converts to string.

public override string ToString()

Returns

string

A string that represents this instance.

TryParse<O>(string, out O?)

Tries to parsing the specified text representing an operation.

public static bool TryParse<O>(string text, out O? operation) where O : CharChainOperation

Parameters

text string

The text.

operation O

The parsed operation.

Returns

bool

True if success.

Type Parameters

O

Exceptions

ArgumentNullException

text

UpdateContext(ChainOperationContext<char>, string, string, IList<ChainNode<char>>, IList<ChainNode<char>>)

Updates the context metadata after executing the operation.

protected void UpdateContext(ChainOperationContext<char> context, string inputTag, string outputTag, IList<ChainNode<char>> refNodes, IList<ChainNode<char>> targetNodes)

Parameters

context ChainOperationContext<char>

The context.

inputTag string

The input tag.

outputTag string

The output tag.

refNodes IList<ChainNode<char>>

The nodes referenced by the operation.

targetNodes IList<ChainNode<char>>

The nodes which should be the target of node-scoped features, if any.

See Also