From 3c635e4e8f18accd3da3f49429511a22201c9c64 Mon Sep 17 00:00:00 2001 From: Creeper Lv Date: Fri, 17 Nov 2023 00:46:31 +0800 Subject: [PATCH] Added Split() as IEnumerator. Added a unit test to test RefString.Split(). --- LibCLCC.NET.NUnit/RefStringTests.cs | 28 +++++++++++++++++++++ LibCLCC.NET/Data/RefString.cs | 38 +++++++++++++++++++++++++++-- LibCLCC.NET/LibCLCC.NET.csproj | 2 +- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 LibCLCC.NET.NUnit/RefStringTests.cs diff --git a/LibCLCC.NET.NUnit/RefStringTests.cs b/LibCLCC.NET.NUnit/RefStringTests.cs new file mode 100644 index 0000000..e702ebe --- /dev/null +++ b/LibCLCC.NET.NUnit/RefStringTests.cs @@ -0,0 +1,28 @@ +using LibCLCC.NET.Data; + +namespace LibCLCC.NET.NUnit +{ + public class RefStringTests + { + string ori="/A/B/C//D\\E"; + [SetUp] + public void Setup() + { + } + [Test] + public void DataTypeTest() + { + RefString BaseString0 = new RefString(ori , 0 , ori.Length); + var e=BaseString0.Split('/','\\'); + var comp=ori.Split('/','\\'); + int i=0; + while(e.MoveNext()) + { + var c=e.Current.FinalizeString(); + Assert.That(c, Is.EqualTo(comp [i])); + i++; + } + + } + } +} \ No newline at end of file diff --git a/LibCLCC.NET/Data/RefString.cs b/LibCLCC.NET/Data/RefString.cs index 352b79b..b7c52c0 100644 --- a/LibCLCC.NET/Data/RefString.cs +++ b/LibCLCC.NET/Data/RefString.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text; +using System.Xml.XPath; namespace LibCLCC.NET.Data { @@ -208,7 +209,7 @@ public readonly int IndexOf(char c , int offset , int count) [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly int IndexOf(string str , int offset) { - return Ref.IndexOf(str , Offset + offset, Length); + return Ref.IndexOf(str , Offset + offset , Length); } /// /// Returns a zero-based index of the first appearance of a given string within this sturct. @@ -220,7 +221,7 @@ public readonly int IndexOf(string str , int offset) /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int IndexOf(string str, int offset , int count) + public readonly int IndexOf(string str , int offset , int count) { return Ref.IndexOf(str , Offset + offset , Math.Min(Length , count)); } @@ -233,6 +234,31 @@ public IEnumerator GetEnumerator() { return iterate(); } + /// + /// Split the string. + /// + /// + /// + public IEnumerator Split(params char [ ] splitters) + { + RefString result = new RefString(this.Ref , Offset , 0); + for (int i = Offset ; i < Length ; i++) + { + var item = this.Ref [ i ]; + foreach (var tester in splitters) + { + if (item == tester) + { + yield return result; + result = new RefString(this.Ref , i + 1 , 0); + goto SKIP; + } + } + result.Length++; + SKIP:; + } + yield return result; + } IEnumerator iterate() { for (int i = Offset ; i < Length ; i++) @@ -245,5 +271,13 @@ IEnumerator IEnumerable.GetEnumerator() { return iterate(); } + /// + /// Convert to a new string. + /// + /// + public string FinalizeString() + { + return Ref [ Offset..(Offset + Length) ]; + } } } diff --git a/LibCLCC.NET/LibCLCC.NET.csproj b/LibCLCC.NET/LibCLCC.NET.csproj index 47f8103..394c209 100644 --- a/LibCLCC.NET/LibCLCC.NET.csproj +++ b/LibCLCC.NET/LibCLCC.NET.csproj @@ -2,7 +2,7 @@ netstandard2.1 - $(VersionPrefix)1.23.24.0 + $(VersionPrefix)1.24.25.0 LICENSE.txt False README.md