Skip to content

Commit

Permalink
Merge pull request #26 from creeperlv/develop
Browse files Browse the repository at this point in the history
Added Split() as IEnumerator.
  • Loading branch information
creeperlv authored Nov 16, 2023
2 parents 368d59b + 3c635e4 commit 4d8d64e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
28 changes: 28 additions & 0 deletions LibCLCC.NET.NUnit/RefStringTests.cs
Original file line number Diff line number Diff line change
@@ -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++;
}

}
}
}
38 changes: 36 additions & 2 deletions LibCLCC.NET/Data/RefString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.XPath;

namespace LibCLCC.NET.Data
{
Expand Down Expand Up @@ -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);
}
/// <summary>
/// Returns a zero-based index of the first appearance of a given string within this sturct.
Expand All @@ -220,7 +221,7 @@ public readonly int IndexOf(string str , int offset)
/// <param name="count"></param>
/// <returns></returns>
[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));
}
Expand All @@ -233,6 +234,31 @@ public IEnumerator<char> GetEnumerator()
{
return iterate();
}
/// <summary>
/// Split the string.
/// </summary>
/// <param name="splitters"></param>
/// <returns></returns>
public IEnumerator<RefString> 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<char> iterate()
{
for (int i = Offset ; i < Length ; i++)
Expand All @@ -245,5 +271,13 @@ IEnumerator IEnumerable.GetEnumerator()
{
return iterate();
}
/// <summary>
/// Convert to a new string.
/// </summary>
/// <returns></returns>
public string FinalizeString()
{
return Ref [ Offset..(Offset + Length) ];
}
}
}
2 changes: 1 addition & 1 deletion LibCLCC.NET/LibCLCC.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>$(VersionPrefix)1.23.24.0</Version>
<Version>$(VersionPrefix)1.24.25.0</Version>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down

0 comments on commit 4d8d64e

Please sign in to comment.