diff --git a/LibCLCC.NET.NUnit/RefStringTests.cs b/LibCLCC.NET.NUnit/RefStringTests.cs
index 53d9491..6bffb7a 100644
--- a/LibCLCC.NET.NUnit/RefStringTests.cs
+++ b/LibCLCC.NET.NUnit/RefStringTests.cs
@@ -1,74 +1,117 @@
using LibCLCC.NET.Data;
+using System.Diagnostics;
namespace LibCLCC.NET.NUnit
{
- public class RefStringTests
- {
- string ori = "/A/B/C//D\\E";
- [SetUp]
- public void Setup()
- {
- }
- [Test]
- public void ParsingTest()
- {
- string input = "ASD123.001DEF";
- RefString A = input;
- A.Offset = 3;
- A.Length = 3;
- {
- Assert.Multiple(() =>
- {
- Assert.That(A.TryParse(out int v), Is.True);
- Assert.That(v, Is.EqualTo(123));
- });
- }
+ public class RefStringTests
+ {
+ string ori = "/A/B/C//D\\E";
+ [SetUp]
+ public void Setup()
+ {
+ }
+ [Test]
+ public void SubStringTest()
+ {
+ string str = "This is a sentence. A very long sentence.";
+ RefString rstr = str;
+ var SubString0 = rstr.Substring(0, 4);
+ {
+ string str2 = "This";
+ Assert.That(SubString0 == str2);
+ }
+ {
+ string str2 = "That";
+ Assert.That(SubString0 != str2);
+ }
+ {
+ string str2 = "Tha";
+ Assert.That(SubString0 != str2);
+ }
+ {
+ string str2 = "This is not equal.";
+ Assert.That(SubString0 != str2);
+ }
+ var SubString1 = rstr.Substring(5);
+ {
+ Assert.That(SubString1 == str.Substring(5));
+ }
+ {
+ Assert.That(SubString1 == ((RefString)str).Substring(5));
+ }
+ {
+ Assert.That(SubString1.StartsWith("is"));
+ }
+ }
+ [Test]
+ public void EndsWithTest()
+ {
+ RefString rstr = "new RefString()";
+ RefString R0 = "()";
+ Assert.That(rstr.EndsWith(R0));
+ Assert.That(rstr.Substring(2).EndsWith(R0));
+ Assert.That(rstr.Substring(0,3).EndsWith("ew"));
+ }
+ [Test]
+ public void ParsingTest()
+ {
+ string input = "ASD123.001DEF";
+ RefString A = input;
+ A.Offset = 3;
+ A.Length = 3;
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(A.TryParse(out int v), Is.True);
+ Assert.That(v, Is.EqualTo(123));
+ });
+ }
- A.Length += 4;
- {
- Assert.Multiple(() =>
- {
- Assert.That(A.TryParse(out float v), Is.True);
- Assert.That(v, Is.EqualTo(123.001f));
- });
- }
+ A.Length += 4;
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(A.TryParse(out float v), Is.True);
+ Assert.That(v, Is.EqualTo(123.001f));
+ });
+ }
- A.Length += 1;
- {
- Assert.Multiple(() =>
- {
- Assert.That(A.TryParse(out double v), Is.True);
- Assert.That(v, Is.EqualTo(123.001));
- });
- }
+ A.Length += 1;
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(A.TryParse(out double v), Is.True);
+ Assert.That(v, Is.EqualTo(123.001));
+ });
+ }
- string Testee_00 = "ASD";
- string Testee_01 = "DEF";
- A.Offset=0;
- A.Length=input.Length;
- Assert.Multiple(() =>
- {
- Assert.That(A.StartsWith(Testee_00), Is.True);
- Assert.That(A.StartsWith(Testee_01), Is.False);
- Assert.That(A.EndsWith(Testee_00), Is.False);
- Assert.That(A.EndsWith(Testee_01), Is.True);
- });
- }
+ string Testee_00 = "ASD";
+ string Testee_01 = "DEF";
+ A.Offset = 0;
+ A.Length = input.Length;
+ Assert.Multiple(() =>
+ {
+ Assert.That(A.StartsWith(Testee_00), Is.True);
+ Assert.That(A.StartsWith(Testee_01), Is.False);
+ Assert.That(A.EndsWith(Testee_00), Is.False);
+ Assert.That(A.EndsWith(Testee_01), Is.True);
+ });
+ }
- [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++;
- }
+ [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 ef002b3..d859757 100644
--- a/LibCLCC.NET/Data/RefString.cs
+++ b/LibCLCC.NET/Data/RefString.cs
@@ -1,394 +1,543 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.XPath;
namespace LibCLCC.NET.Data
{
- ///
- /// Reference String.
- /// Use for reduce memory consumption.
- ///
- public struct RefString : IEnumerable, IEnumerable
- {
- ///
- /// The NULL reference.
- ///
- public readonly static RefString NULL = new RefString() { Ref = null };
- ///
- /// Referred string
- ///
- public string Ref;
- ///
- /// Offset in Ref
- ///
- public int Offset;
- ///
- /// Length of the RefString
- ///
- public int Length;
- ///
- /// Create a RefString.
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public RefString(string string_value, int offset, int length)
- {
- Ref = string_value;
- Offset = offset;
- Length = length;
- }
- ///
- /// Get certain character
- ///
- ///
- ///
- public char this[int index]
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- return Ref[index + Offset];
- }
- }
+ ///
+ /// Reference String.
+ /// Use for reduce memory consumption.
+ ///
+ public struct RefString : IEnumerable, IEnumerable
+ {
+ ///
+ /// The NULL reference.
+ ///
+ public readonly static RefString NULL = new RefString() { Ref = null };
+ ///
+ /// Referred string
+ ///
+ public string Ref;
+ ///
+ /// Offset in Ref
+ ///
+ public int Offset;
+ ///
+ /// Length of the RefString
+ ///
+ public int Length;
+ ///
+ /// Create a RefString.
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public RefString(string string_value, int offset, int length)
+ {
+ Ref = string_value;
+ Offset = offset;
+ Length = length;
+ }
+ ///
+ /// Get certain character
+ ///
+ ///
+ ///
+ public char this[int index]
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ return Ref[index + Offset];
+ }
+ }
- ///
- /// Treat it as a read-only stan
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ReadOnlySpan AsReadOnlySpan() => (ReadOnlySpan)this;
- ///
- /// Convert a string to a RefString
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static implicit operator RefString(string s) => new RefString { Ref = s, Offset = 0, Length = s.Length };
- ///
- /// Convert a RefString to ReadOnlySpan
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static implicit operator ReadOnlySpan(RefString s)
- {
- if (s.Offset + s.Length > s.Ref.Length)
- {
- throw new IndexOutOfRangeException();
- }
- return s.Ref.AsSpan(s.Offset, s.Length);
- }
- ///
- /// If the referred string is null.
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly bool IsNull() => Ref == null;
- ///
- /// If the referred string is not null.
- ///
- ///
+ ///
+ /// Treat it as a read-only stan
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public ReadOnlySpan AsReadOnlySpan() => (ReadOnlySpan)this;
+ ///
+ /// Convert a string to a RefString
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator RefString(string s) => new RefString { Ref = s, Offset = 0, Length = s.Length };
+ ///
+ /// Convert a RefString to ReadOnlySpan
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator ReadOnlySpan(RefString s)
+ {
+ if (s.Offset + s.Length > s.Ref.Length)
+ {
+ throw new IndexOutOfRangeException();
+ }
+ return s.Ref.AsSpan(s.Offset, s.Length);
+ }
+ ///
+ /// If the referred string is null.
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly bool IsNull() => Ref == null;
+ ///
+ /// If the referred string is not null.
+ ///
+ ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly bool IsNotNull() => Ref != null;
- ///
- /// Move the offset of the string. The length will be adjusted as well.
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static RefString operator +(RefString L, int R)
- {
- RefString result = L;
- result.Ref = L.Ref;
- result.Offset += R;
- result.Length -= R;
- if (result.Length < 0) throw new IndexOutOfRangeException();
- return result;
- }
- ///
- /// Move the offset of the string. The length will be adjusted as well.
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static RefString operator -(RefString L, int R)
- {
- RefString result = L;
- result.Ref = L.Ref;
- result.Offset -= R;
- result.Length += R;
- if (result.Offset < 0) throw new IndexOutOfRangeException();
- return result;
- }
- ///
- /// Check if equal to a string.
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(RefString L, string R)
- {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly bool IsNotNull() => Ref != null;
+ ///
+ /// Move the offset of the string. The length will be adjusted as well.
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static RefString operator +(RefString L, int R)
+ {
+ RefString result = L;
+ result.Ref = L.Ref;
+ result.Offset += R;
+ result.Length -= R;
+ if (result.Length < 0) throw new IndexOutOfRangeException();
+ return result;
+ }
+ ///
+ /// Move the offset of the string. The length will be adjusted as well.
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static RefString operator -(RefString L, int R)
+ {
+ RefString result = L;
+ result.Ref = L.Ref;
+ result.Offset -= R;
+ result.Length += R;
+ if (result.Offset < 0) throw new IndexOutOfRangeException();
+ return result;
+ }
+ ///
+ /// Check if equal to a string.
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator ==(RefString L, string R)
+ {
- var i = L.Ref.IndexOf(R, L.Offset);
- var Len = R.Length;
- return (i == 0 && Len == L.Length);
- }
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool StartsWith(string R)
- {
- return this.Ref.IndexOf(R, Offset) == 0;
- }
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool StartsWith(string R, int _offset)
- {
- return this.Ref.IndexOf(R, Offset + _offset) == 0;
- }
- char ToOtherCase(char c)
- {
- if (c >= 'A' && c <= 'Z')
- {
- return (char)(c - 'A' + 'a');
- }
- if (c >= 'a' && c <= 'z')
- {
- return (char)(c - +'A' - 'a');
- }
- return c;
- }
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool StartsWith(string R, int _offset, bool CaseIrrelevant)
- {
- if (CaseIrrelevant)
- {
+ var startI = L.Ref.IndexOf(R, L.Offset) - L.Offset;
+ var Len = R.Length;
+ if (startI == 0 && Len == L.Length)
+ {
+ for (int i = 0; i < Len; i++)
+ {
+ if (L[i] != R[i])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+ ///
+ /// Compare 2 RefString even if the internal Referenced strings are different.
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator ==(RefString L, RefString R)
+ {
- for (int i = 0; i < R.Length; i++)
- {
- char v = R[i];
- if (Ref[Offset + _offset + i] != v && Ref[Offset + _offset + i] != ToOtherCase(v))
- {
- return false;
- }
- }
- return true;
- }
- else
- {
- return this.Ref.IndexOf(R, Offset + _offset) == 0;
- }
- }
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool EndsWith(string R)
- {
- return this.Ref.IndexOf(R, Offset) == (Length - R.Length);
- }
- ///
- /// Move the offset of the string. The length will be adjusted as well.
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(RefString L, string R)
- {
- var i = L.Ref.IndexOf(R, L.Offset);
- var Len = R.Length;
- return (i != 0 || Len != L.Length);
- }
- ///
- /// Retrieves a substring. The substring has a given start position and continues to the end of the RefString.
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly RefString Substring(int StartIndex)
- {
- return this + StartIndex;
- }
- ///
- /// Retrieves a substring. The substring has a given start position and has a given length.
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly RefString Substring(int StartIndex, int SubStringLength)
- {
- var r = this + StartIndex;
- r.Length = SubStringLength;
- return r;
- }
- ///
- /// Returns a zero-based index of the first appearance of a given char within this sturct.
- /// The method returns -1 if the target is not found in this instance.
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly int IndexOf(char c)
- {
- return Ref.IndexOf(c, Offset, Length);
- }
- ///
- /// Returns a zero-based index of the first appearance of a given string within this sturct.
- /// The method returns -1 if the target is not found in this instance.
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly int IndexOf(string str)
- {
- return Ref.IndexOf(str, Offset, Length);
- }
- ///
- /// Returns a zero-based index of the first appearance of a given char within this sturct.
- /// The method returns -1 if the target is not found in this instance.
- /// The search starts at a given position.
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly int IndexOf(char c, int offset)
- {
- return Ref.IndexOf(c, Offset + offset, Length);
- }
- ///
- /// Returns a zero-based index of the first appearance of a given char within this sturct.
- /// The method returns -1 if the target is not found in this instance.
- /// The search starts at a given position.
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly int IndexOf(char c, int offset, int count)
- {
- return Ref.IndexOf(c, Offset + offset, Math.Min(Length, count));
- }
- ///
- /// Returns a zero-based index of the first appearance of a given string within this sturct.
- /// The method returns -1 if the target is not found in this instance.
- /// The search starts at a given position.
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly int IndexOf(string str, int offset)
- {
- return Ref.IndexOf(str, Offset + offset, Length);
- }
- ///
- /// Returns a zero-based index of the first appearance of a given string within this sturct.
- /// The method returns -1 if the target is not found in this instance.
- /// The search starts at a given position.
- ///
- ///
- ///
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly int IndexOf(string str, int offset, int count)
- {
- return Ref.IndexOf(str, Offset + offset, Math.Min(Length, count));
- }
- ///
- /// Iterate through characters in range [offset..offset+length].
- ///
- ///
+ var Len = R.Length;
+ if (Len == L.Length)
+ {
+ for (int i = 0; i < Len; i++)
+ {
+ if (L[i] != R[i])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+ ///
+ /// Compare 2 RefString even if the internal Referenced strings are different.
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator !=(RefString L, RefString R)
+ {
+ return !(L == R);
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool StartsWith(string R)
+ {
+ return (Ref.IndexOf(R, Offset) - Offset) == 0;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool StartsWith(string R, int _offset)
+ {
+ return (Ref.IndexOf(R, Offset + _offset) - Offset) == 0;
+ }
+ char ToOtherCase(char c)
+ {
+ if (c >= 'A' && c <= 'Z')
+ {
+ return (char)(c - 'A' + 'a');
+ }
+ if (c >= 'a' && c <= 'z')
+ {
+ return (char)(c - +'A' - 'a');
+ }
+ return c;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool StartsWith(string R, int _offset, bool CaseIrrelevant)
+ {
+ if (CaseIrrelevant)
+ {
- 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;
- }
- ///
- /// Split the string.
- ///
- ///
- ///
- public RefStringSplitQuery SplitQuery(params char[] splitters)
- {
- return new RefStringSplitQuery { query = Split(splitters) };
- }
- IEnumerator iterate()
- {
- for (int i = Offset; i < Length; i++)
- {
- yield return Ref[i];
- }
- yield break;
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return iterate();
- }
- ///
- /// Convert to a new string.
- ///
- ///
- public string FinalizeString()
- {
- return Ref[Offset..(Offset + Length)];
- }
- }
+ for (int i = 0; i < R.Length; i++)
+ {
+ char v = R[i];
+ if (Ref[Offset + _offset + i] != v && Ref[Offset + _offset + i] != ToOtherCase(v))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ else
+ {
+ return this.Ref.IndexOf(R, Offset + _offset) - Offset == 0;
+ }
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool EndsWith(string R)
+ {
+ if (R.Length > Length) return false;
+ return this.IndexOf(R, Length - R.Length) == Length - R.Length;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool EndsWith(RefString R)
+ {
+ if (R.Length > Length) return false;
+ return IndexOfSL(R, Length - R.Length) == Length - R.Length;
+ }
+ ///
+ /// The opposite of ==
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static bool operator !=(RefString L, string R)
+ {
+ return !(L == R);
+ }
+ ///
+ /// Retrieves a substring. The substring has a given start position and continues to the end of the RefString.
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly RefString Substring(int StartIndex)
+ {
+ return this + StartIndex;
+ }
+ ///
+ /// Retrieves a substring. The substring has a given start position and has a given length.
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly RefString Substring(int StartIndex, int SubStringLength)
+ {
+ var r = this + StartIndex;
+ if (r.Length < SubStringLength)
+ {
+ throw new ArgumentOutOfRangeException(nameof(SubStringLength));
+ }
+ r.Length = SubStringLength;
+ return r;
+ }
+ ///
+ /// Returns a zero-based index of the first appearance of a given char within this sturct.
+ /// The method returns -1 if the target is not found in this instance.
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(char c)
+ {
+ return Ref.IndexOf(c, Offset, Length) - Offset;
+ }
+ ///
+ /// Returns a zero-based index of the first appearance of a given string within this sturct.
+ /// The method returns -1 if the target is not found in this instance.
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(string str)
+ {
+ return Ref.IndexOf(str, Offset, Length) - Offset;
+ }
+ ///
+ /// Will create Reference Object!
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(RefString str)
+ {
+ return Ref.IndexOf(str.FinalizeString(), Offset, Length) - Offset;
+ }
+ ///
+ /// Will create Reference Object!
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(RefString str, int Offset)
+ {
+ return IndexOf(str.FinalizeString(), Offset);
+ }
+ ///
+ /// Slow version of IndexOf, but use less memory.
+ ///
+ ///
+ ///
+ public readonly int IndexOfSL(RefString str)
+ {
+ for (int i = 0; i < this.Length - str.Length; i++)
+ {
+ var L = this + i;
+ L.Length = str.Length;
+ if (L == str)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+ ///
+ /// Slow version of IndexOf, but use less memory.
+ ///
+ ///
+ ///
+ ///
+ public readonly int IndexOfSL(RefString str, int Offset)
+ {
+ for (int i = Offset; i <= Length - str.Length; i++)
+ {
+ var L = this + i;
+ L.Length = str.Length;
+ if (L == str)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+ ///
+ /// Returns a zero-based index of the first appearance of a given char within this sturct.
+ /// The method returns -1 if the target is not found in this instance.
+ /// The search starts at a given position.
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(char c, int offset)
+ {
+ return Ref.IndexOf(c, Offset + offset, Length) - Offset;
+ }
+ ///
+ /// Returns a zero-based index of the first appearance of a given char within this sturct.
+ /// The method returns -1 if the target is not found in this instance.
+ /// The search starts at a given position.
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(char c, int offset, int count)
+ {
+ return Ref.IndexOf(c, Offset + offset, Math.Min(Length, count)) - Offset;
+ }
+ ///
+ /// Returns a zero-based index of the first appearance of a given string within this sturct.
+ /// The method returns -1 if the target is not found in this instance.
+ /// The search starts at a given position.
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(string str, int offset)
+ {
+ int startIndex = Offset + offset;
+ return Ref.IndexOf(str, startIndex, Length - offset) - Offset;
+ }
+ ///
+ /// Returns a zero-based index of the first appearance of a given string within this sturct.
+ /// The method returns -1 if the target is not found in this instance.
+ /// The search starts at a given position.
+ ///
+ ///
+ ///
+ ///
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly int IndexOf(string str, int offset, int count)
+ {
+ return Ref.IndexOf(str, Offset + offset, Math.Min(Length, count)) - Offset;
+ }
+ ///
+ /// Iterate through characters in range [offset..offset+length].
+ ///
+ ///
+
+ 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;
+ }
+ ///
+ /// Split the string.
+ ///
+ ///
+ ///
+ public RefStringSplitQuery SplitQuery(params char[] splitters)
+ {
+ return new RefStringSplitQuery { query = Split(splitters) };
+ }
+ IEnumerator iterate()
+ {
+ for (int i = Offset; i < Length; i++)
+ {
+ yield return Ref[i];
+ }
+ yield break;
+ }
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return iterate();
+ }
+ ///
+ /// Convert to a new string.
+ ///
+ ///
+ public string FinalizeString()
+ {
+ return Ref[Offset..(Offset + Length)];
+ }
+ ///
+ /// Equality to any obj.
+ ///
+ ///
+ ///
+ public override bool Equals(object obj)
+ {
+ if (obj is string s)
+ {
+ return this == s;
+ }
+ return base.Equals(obj);
+ }
+ ///
+ /// Get the hash code of the RefString.
+ ///
+ ///
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+ ///
+ /// ToString via FinalizeString().
+ ///
+ ///
+ public override string ToString()
+ {
+ return FinalizeString();
+ }
+ }
}
diff --git a/LibCLCC.NET/LibCLCC.NET.csproj b/LibCLCC.NET/LibCLCC.NET.csproj
index be1e274..348bfb4 100644
--- a/LibCLCC.NET/LibCLCC.NET.csproj
+++ b/LibCLCC.NET/LibCLCC.NET.csproj
@@ -2,7 +2,7 @@
netstandard2.1
- $(VersionPrefix)1.29.30.0
+ $(VersionPrefix)1.30.31.0
LICENSE.txt
False
README.md