add unicode figure

This commit is contained in:
Nitload
2026-02-23 19:54:21 +08:00
parent 36279a6aae
commit d99c1e3aa6
6 changed files with 119 additions and 94 deletions
@@ -1,9 +1,9 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="CapacityFixedList" // file="CapacityFixedList"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -47,11 +47,13 @@ namespace StgSharp.Collections
{ {
private T[] _values; private T[] _values;
private int capacity, _index; private readonly int _capacity;
private int _index;
public CapacityFixedList(int size) public CapacityFixedList(int size)
{ {
_values = new T[size]; _values = new T[size];
_capacity = size;
} }
public CapacityFixedList(ReadOnlySpan<T> values) public CapacityFixedList(ReadOnlySpan<T> values)
@@ -62,16 +64,7 @@ namespace StgSharp.Collections
public T this[int index] public T this[int index]
{ {
get => index < _index ? _values[index] : throw new ArgumentOutOfRangeException(nameof(index)); get => index < _index ? _values[index] : throw new ArgumentOutOfRangeException(nameof(index));
set set => _values[index] = index < _index ? value : throw new ArgumentOutOfRangeException(nameof(index));
{
if (index < _index)
{
_values[index] = value;
} else
{
throw new ArgumentOutOfRangeException(nameof(index));
}
}
} }
public bool IsReadOnly => false; public bool IsReadOnly => false;
@@ -80,7 +73,7 @@ namespace StgSharp.Collections
public void Add(T item) public void Add(T item)
{ {
if (_index < capacity - 1) if (_index < _capacity - 1)
{ {
_index++; _index++;
this[_index] = item; this[_index] = item;
@@ -89,7 +82,7 @@ namespace StgSharp.Collections
public void Clear() public void Clear()
{ {
_values = new T[capacity]; _values = new T[_capacity];
_index = 0; _index = 0;
} }
@@ -2,8 +2,8 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="CapacityFixedStack" // file="CapacityFixedStack"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -57,7 +57,11 @@ namespace StgSharp.Collections
public int Capacity => _values.Length; public int Capacity => _values.Length;
public ReadOnlySpan<T> AsSpan() => _values.AsSpan(0, _index); [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ReadOnlySpan<T> AsSpan()
{
return _values.AsSpan(0, _index);
}
public void Clear() public void Clear()
{ {
@@ -1,27 +1,30 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="NotEnumerableList" // file="NotEnumerableList.cs"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person
// of this software and associated documentation files (the "Software"), to deal // obtaining a copy of this software and associated documentation
// in the Software without restriction, including without limitation the rights // files (the “Software”), to deal in the Software without restriction,
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // including without limitation the rights to use, copy, modify, merge,
// copies of the Software, and to permit persons to whom the Software is // publish, distribute, sublicense, and/or sell copies of the Software,
// furnished to do so, subject to the following conditions: // and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and
// copies or substantial portions of the Software. // this permission notice shall be included in all copies
// or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED “AS IS”,
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// SOFTWARE. // ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -113,7 +116,10 @@ namespace StgSharp.Collections
/// Returns a span over the live portion of the bag (0..Count-1). /// Returns a span over the live portion of the bag (0..Count-1).
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan() => new Span<T>(_items, 0, Count); public Span<T> AsSpan()
{
return new Span<T>(_items, 0, Count);
}
/// <summary> /// <summary>
/// Clears all elements and zeroes out references to avoid retention. Count becomes 0. /// Clears all elements and zeroes out references to avoid retention. Count becomes 0.
@@ -130,7 +136,10 @@ namespace StgSharp.Collections
/// released. Use only when you are certain old references can remain. /// released. Use only when you are certain old references can remain.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void FastClear() => Count = 0; public void FastClear()
{
Count = 0;
}
/// <summary> /// <summary>
/// Removes the first occurrence of value (unordered). Does nothing if not found. /// Removes the first occurrence of value (unordered). Does nothing if not found.
+13 -24
View File
@@ -2,8 +2,8 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Counter" // file="Counter"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -30,7 +30,7 @@ using System.Numerics;
namespace StgSharp namespace StgSharp
{ {
public class Counter<T> where T : unmanaged, INumber<T> public class Counter<T> where T: unmanaged, INumber<T>
{ {
internal dynamic _value; internal dynamic _value;
@@ -39,11 +39,7 @@ namespace StgSharp
internal readonly T _defaultIncrement; internal readonly T _defaultIncrement;
internal readonly T _defaultValue; internal readonly T _defaultValue;
public Counter( public Counter(T defaultValue, T defaultIncrement, T defaultDecrement)
T defaultValue,
T defaultIncrement,
T defaultDecrement
)
{ {
_value = defaultValue; _value = defaultValue;
_defaultValue = defaultValue; _defaultValue = defaultValue;
@@ -63,9 +59,7 @@ namespace StgSharp
set => _value = value; set => _value = value;
} }
public void Add( public void Add(T value)
T value
)
{ {
_value += value; _value += value;
} }
@@ -85,34 +79,29 @@ namespace StgSharp
_value = _defaultValue; _value = _defaultValue;
} }
public void Sub( public void Sub(T value)
T value
)
{ {
_value -= value; _value -= value;
} }
public override string ToString() => Value.ToString(); public override string ToString()
{
return Value.ToString() ?? string.Empty;
}
public static Counter<T> operator --( public static Counter<T> operator --(Counter<T> counter)
Counter<T> counter
)
{ {
counter?.QuickSub(); counter?.QuickSub();
return counter; return counter;
} }
public static Counter<T> operator ++( public static Counter<T> operator ++(Counter<T> counter)
Counter<T> counter
)
{ {
counter?.QuickAdd(); counter?.QuickAdd();
return counter; return counter;
} }
public static implicit operator T( public static implicit operator T(Counter<T> counter)
Counter<T> counter
)
{ {
return counter switch return counter switch
{ {
+3 -3
View File
@@ -28,21 +28,21 @@
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization> <WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v145</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v145</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='PerformanceDebug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='PerformanceDebug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v145</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
@@ -2,8 +2,8 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="RegexTokenReader" // file="RegexTokenReader"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -45,9 +45,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
public RegexTokenReader() { } public RegexTokenReader() { }
public RegexTokenReader( public RegexTokenReader(string source)
string source
)
{ {
_source = source; _source = source;
} }
@@ -63,9 +61,50 @@ namespace StgSharp.RegularAnalysis.TextRegex
if (pos + 1 == _source.Length) { if (pos + 1 == _source.Length) {
throw new InvalidOperationException("Unclosed char"); throw new InvalidOperationException("Unclosed char");
} }
if (_source[pos + 1] == 'x')
{
string value = _source[(pos + 1)..(pos + 3)];
pos += 4;
if (uint.TryParse(value, out uint code) && Rune.TryCreate(code, out Rune result))
{
return new Token<RegexElementLabel>(result.ToString(), 0, pos, RegexElementLabel.UNIT);
} else
{
throw new InvalidCastException($"Failed to convert {value} to a valid ascii code point.");
}
} else if (_source[pos + 1] == 'u')
{
string value = _source[(pos + 1)..(pos + 5)];
pos += 6;
if (uint.TryParse(value, out uint code) && Rune.TryCreate(code, out Rune result))
{
return new Token<RegexElementLabel>(result.ToString(), 0, pos, RegexElementLabel.UNIT);
} else
{
throw new InvalidCastException($"Failed to convert {value} to a valid unicode code point.");
}
} else if (_source[pos + 1] == 'p')
{
int i = pos + 2;
if (_source[i] != '{') {
throw new InvalidOperationException("Invalid Unicode property escape sequence.");
}
for (; i < _source.Length; i++)
{
if (_source[i] == '}')
{
position = i + 1;
return new Token<RegexElementLabel>(_source[(pos)..(i + 1)], 0, pos,
RegexElementLabel.UNIT_SET);
}
}
throw new InvalidOperationException("Unclosed Unicode property escape sequence.");
} else
{
position = pos + 2; position = pos + 2;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 2)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 2)], 0, pos,
RegexElementLabel.UNIT_SET); RegexElementLabel.UNIT_SET);
}
case '[': case '[':
for (int i = pos + 1; i < _source.Length; i++) for (int i = pos + 1; i < _source.Length; i++)
{ {
@@ -73,24 +112,21 @@ namespace StgSharp.RegularAnalysis.TextRegex
{ {
int length = (i - pos - 1); int length = (i - pos - 1);
position = i + 1; position = i + 1;
return new Token<RegexElementLabel>(_source[(pos)..(i + 1)], 0, return new Token<RegexElementLabel>(_source[(pos)..(i + 1)], 0, position,
position,
RegexElementLabel.UNIT_SET); RegexElementLabel.UNIT_SET);
} }
} }
throw new InvalidOperationException("Unclosed character set"); throw new InvalidOperationException("Unclosed character set");
case '|': case '|':
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.ALT);
RegexElementLabel.ALT);
case '(': case '(':
// very comlex here // very comlex here
return ReadGroupBeginToken(); return ReadGroupBeginToken();
case ')': case ')':
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.GROUP_END);
RegexElementLabel.GROUP_END);
case '{': case '{':
for (int i = pos + 1; i < _source.Length; i++) for (int i = pos + 1; i < _source.Length; i++)
{ {
@@ -105,25 +141,19 @@ namespace StgSharp.RegularAnalysis.TextRegex
case '*' or '+': case '*' or '+':
int count = _source[pos + 1] == '?' ? 2 : 1; int count = _source[pos + 1] == '?' ? 2 : 1;
position = pos + count; position = pos + count;
return new Token<RegexElementLabel>(_source[(pos)..(pos + count)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + count)], 0, pos, RegexElementLabel.COUNT);
RegexElementLabel.COUNT);
case '?': case '?':
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.COUNT);
RegexElementLabel.COUNT);
case '.': case '.':
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.UNIT);
RegexElementLabel.UNIT);
default: default:
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.UNIT);
RegexElementLabel.UNIT);
} }
} }
public bool TryReadToken( public bool TryReadToken(out Token<RegexElementLabel> t)
out Token<RegexElementLabel> t
)
{ {
if (IsEmpty) if (IsEmpty)
{ {