Added settings classes for CSS; added Register parsing

This commit is contained in:
schnulller
2022-05-18 04:38:57 +02:00
parent 2ffd46cd62
commit f1743fcf39
14 changed files with 882 additions and 258 deletions

View File

@@ -5,28 +5,30 @@ using System.Text;
using System.Collections.Generic;
using System;
public class XMLHelper {
public class XMLHelper
{
private IReader _in;
private StringBuilder _target;
private List<(Func<Tag, bool>, Action<StringBuilder, Tag>)> _OTag_Funcs;
private List<(Func<Tag, bool>, Action<StringBuilder, Tag>)> _STag_Funcs;
private List<(Func<Tag, bool>, Action<StringBuilder, Tag>)> _CTag_Funcs;
private List<(Func<Text, bool>, Action<StringBuilder, Text>)> _Text_Funcs;
private List<(Func<Whitespace, bool>, Action<StringBuilder, Whitespace>)> _WS_Funcs;
private List<(Func<Tag, bool>, Action<StringBuilder, Tag>)>? _OTag_Funcs;
private List<(Func<Tag, bool>, Action<StringBuilder, Tag>)>? _STag_Funcs;
private List<(Func<Tag, bool>, Action<StringBuilder, Tag>)>? _CTag_Funcs;
private List<(Func<Text, bool>, Action<StringBuilder, Text>)>? _Text_Funcs;
private List<(Func<Whitespace, bool>, Action<StringBuilder, Whitespace>)>? _WS_Funcs;
private bool _deleteLeadingWS;
private bool _deleteTrailingWS;
public XMLHelper(
IReader input,
StringBuilder target,
List<(Func<Tag, bool>, Action<StringBuilder, Tag>)> OTag_Funcs = null,
List<(Func<Tag, bool>, Action<StringBuilder, Tag>)> STag_Funcs = null,
List<(Func<Tag, bool>, Action<StringBuilder, Tag>)> CTag_Funcs = null,
List<(Func<Text, bool>, Action<StringBuilder, Text>)> Text_Funcs = null,
List<(Func<Whitespace, bool>, Action<StringBuilder, Whitespace>)> WS_Funcs = null,
StringBuilder target,
List<(Func<Tag, bool>, Action<StringBuilder, Tag>)>? OTag_Funcs = null,
List<(Func<Tag, bool>, Action<StringBuilder, Tag>)>? STag_Funcs = null,
List<(Func<Tag, bool>, Action<StringBuilder, Tag>)>? CTag_Funcs = null,
List<(Func<Text, bool>, Action<StringBuilder, Text>)>? Text_Funcs = null,
List<(Func<Whitespace, bool>, Action<StringBuilder, Whitespace>)>? WS_Funcs = null,
bool deleteLeadingWS = false,
bool deleteTrailingWS = false
) {
)
{
if (input == null || target == null) throw new ArgumentNullException();
_in = input;
@@ -52,36 +54,45 @@ public class XMLHelper {
_in.Whitespace += OnWS;
}
void OnOTag(object _, Tag tag) {
foreach(var entry in _OTag_Funcs)
if (entry.Item1(tag)) entry.Item2(_target, tag);
void OnOTag(object _, Tag tag)
{
if (_OTag_Funcs != null)
foreach (var entry in _OTag_Funcs)
if (entry.Item1(tag)) entry.Item2(_target, tag);
}
void OnText(object _, Text text) {
void OnText(object _, Text text)
{
if (_deleteLeadingWS) text.Value = text.Value.TrimStart();
if (_deleteTrailingWS) text.Value = text.Value.TrimEnd();
foreach(var entry in _Text_Funcs)
foreach (var entry in _Text_Funcs)
if (entry.Item1(text)) entry.Item2(_target, text);
}
void OnSTag(object _, Tag tag) {
foreach(var entry in _STag_Funcs)
void OnSTag(object _, Tag tag)
{
foreach (var entry in _STag_Funcs)
if (entry.Item1(tag)) entry.Item2(_target, tag);
}
void OnCTag (object _, Tag tag) {
void OnCTag(object _, Tag tag)
{
foreach (var entry in _CTag_Funcs)
if (entry.Item1(tag)) entry.Item2(_target, tag);
}
void OnWS (object _, Whitespace ws) {
foreach (var entry in _WS_Funcs) {
void OnWS(object _, Whitespace ws)
{
foreach (var entry in _WS_Funcs)
{
if (entry.Item1(ws)) entry.Item2(_target, ws);
}
}
internal void Dispose() {
if (_in != null) {
internal void Dispose()
{
if (_in != null)
{
if (_OTag_Funcs != null)
_in.OpenTag -= OnOTag;
if (_STag_Funcs != null)
@@ -95,7 +106,8 @@ public class XMLHelper {
}
}
~XMLHelper() {
~XMLHelper()
{
Dispose();
}
}