From 73b222bbc6c507061287423352b3003e8c7fcb4e Mon Sep 17 00:00:00 2001 From: Nitload Date: Mon, 2 Feb 2026 00:38:15 +0800 Subject: [PATCH] add node type --- .../RegulartMachine/Node.Char.cs | 110 ++++++++---------- 1 file changed, 48 insertions(+), 62 deletions(-) diff --git a/StgSharp.RegularAnalysis/RegulartMachine/Node.Char.cs b/StgSharp.RegularAnalysis/RegulartMachine/Node.Char.cs index ee078eed..e78a3826 100644 --- a/StgSharp.RegularAnalysis/RegulartMachine/Node.Char.cs +++ b/StgSharp.RegularAnalysis/RegulartMachine/Node.Char.cs @@ -1,9 +1,9 @@ -//----------------------------------------------------------------------- +//----------------------------------------------------------------------- // ----------------------------------------------------------------------- -// file="RegularExpression.Node.Char" +// file="Node.Char" // Project: StgSharp -// AuthorGroup: Nitload -// Copyright (c) Nitload. All rights reserved. +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -34,74 +34,60 @@ using System.Text; using System.Threading.Tasks; namespace StgSharp.RegularAnalysis -{ - internal class RegularExpressionCharNode : RegularStateNode +{ + internal class RegularExpressionEpsilonNode : RegularStateNode + { + } + + + internal class RegularExpressionCharNode : RegularStateNode + { + + private char _char; + + public RegularExpressionCharNode(char c) { - - private char _char; - - public RegularExpressionCharNode( - char c - ) - { - _char = c; - } - - public override NodeType Type => NodeType.CHAR; - - public override bool IsValidateFrom( - RegularStateNode former, - RegularContext context - ) - { - int pos = context.Position; - char c = context.CurrentCharSpan[pos + 1]; - return c == _char; - } - + _char = c; } - internal class RegularExpressionCharsetNode : RegularStateNode + public override NodeType Type => NodeType.CHAR; + + public override bool IsValidateFrom(RegularStateNode former, RegularContext context) { + int pos = context.Position; + char c = context.CurrentCharSpan[pos + 1]; + return c == _char; + } - private bool _isNegated; - private HashSet _charset; + } - public RegularExpressionCharsetNode( - IEnumerable charset, - bool isNegated = false - ) - { - _charset = new(charset); - _isNegated = isNegated; - } + internal class RegularExpressionCharsetNode : RegularStateNode + { - public RegularExpressionCharsetNode( - ReadOnlySpan charset, - bool isNegated = false - ) - { - _charset = new(charset.Length); - foreach (char item in _charset) { - _charset.Add(item); - } - _isNegated = isNegated; - } + private bool _isNegated; + private HashSet _charset; - public override NodeType Type => NodeType.CHARSET; + public RegularExpressionCharsetNode(IEnumerable charset, bool isNegated = false) + { + _charset = new(charset); + _isNegated = isNegated; + } - public override bool IsValidateFrom( - RegularStateNode former, - RegularContext context - ) - { - int pos = context.Position; - char c = context.CurrentCharSpan[pos + 1]; - bool contains = _charset.Contains(c); - return _isNegated ? !contains : contains; - } + public RegularExpressionCharsetNode(ReadOnlySpan charset, bool isNegated = false) + { + _charset = new(charset.Length); + _isNegated = isNegated; + } - + public override NodeType Type => NodeType.CHARSET; + + public override bool IsValidateFrom(RegularStateNode former, RegularContext context) + { + int pos = context.Position; + char c = context.CurrentCharSpan[pos + 1]; + bool contains = _charset.Contains(c); + return _isNegated ? !contains : contains; + } } }