4 using System.Collections.Generic;
6 using System.Text.RegularExpressions;
36 Substitute(
new Regex(regex, RegexOptions.Singleline), with);
64 if (
string.IsNullOrWhiteSpace(
result))
return "";
72 public virtual void Add() { }
75 public virtual bool More() =>
false;
84 #region Inner Template 85 private class InnerTemplate :
Template {
87 private string template;
88 private readonly StringBuilder builder =
new StringBuilder();
90 internal readonly List<(int left, int right, string value)> matches =
91 new List<(int left, int right, string value)>();
94 public override void Add() {
99 public override bool More() {
100 if (match < matches.Count) {
101 var left = parent.
result.Substring(0, matches[match].left);
102 var right = parent.
result.Substring(matches[match].right);
103 parent.
result = $
"{left}{builder}{right}";
106 if (--match < 0)
return false;
107 template = matches[match].value;
111 public override void Dispose() {
122 inner.matches.Clear();
123 for (var match = regex.Match(
result); match.Success; match = match.NextMatch())
124 if (match.Groups.Count >= 2)
125 inner.matches.Add((match.Index, match.Index + match.Length, match.Groups[1].Value));
126 inner.match = inner.matches.Count;
130 public Template Inner(
string regex) =>
Inner(
new Regex(regex, RegexOptions.Singleline));
virtual void Add()
//#TBD#//
virtual bool More()
//#TBD#//
Template Inner(Regex regex)
//#TBD#//
Template And(string regex, string with)
//#TBD#//
List< Substitution > substitutions
//#TBD#//
string Result()
//#TBD#//
static Template Instance
//#TBD#//
Template Substitute(Regex regex, string with)
//#TBD#//
Template Substitute(string regex, string with)
//#TBD#//
Template From(string text)
//#TBD#//