public void IndexOfUnicodeCodePoint(int expected, string s, uint codePointValue) { Utf8String u8s = new Utf8String(s); UnicodeCodePoint codePoint = (UnicodeCodePoint)codePointValue; Assert.Equal(expected, u8s.IndexOf(codePoint)); }
public void IndexOfTests(int expected, string s, string substring) { Utf8String utf8s = new Utf8String(s); Utf8String utf8substring = new Utf8String(substring); Assert.Equal(expected, utf8s.IndexOf(utf8substring)); }
public static void Searching_StandaloneSurrogate_Fails() { Utf8String utf8String = u8("\ud800\udfff"); Assert.False(utf8String.Contains('\ud800')); Assert.False(utf8String.Contains('\udfff')); Assert.Equal(-1, utf8String.IndexOf('\ud800')); Assert.Equal(-1, utf8String.IndexOf('\udfff')); Assert.False(utf8String.StartsWith('\ud800')); Assert.False(utf8String.StartsWith('\udfff')); Assert.False(utf8String.EndsWith('\ud800')); Assert.False(utf8String.EndsWith('\udfff')); }
public unsafe void IndexOfNonOccuringSingleCodePointConstructFromSpan() { TestCase[] testCases = new TestCase[] { new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 5000000), new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 5000000), new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 500), new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 500) }; foreach (TestCase testData in testCases) { string s = testData.String; Utf8String utf8s = new Utf8String(s); fixed(byte *bytes = utf8s.CopyBytes()) { utf8s = new Utf8String(new Span <byte>(bytes, utf8s.Length)); int iterations = testData.Iterations; _timer.Restart(); while (iterations-- != 0) { int p = utf8s.IndexOf(31); } PrintTime(testData); } } }
public void IndexOfUtf8CharacterTest(string s, char character) { int expected = s.IndexOf(character); Utf8String u8s = new Utf8String(s); byte u8codeUnit = (byte)(character); Assert.Equal(expected, u8s.IndexOf(u8codeUnit)); }
public static void Contains_And_IndexOf_CharRune_Ordinal(Utf8String utf8String, Rune searchValue, int expectedIndex) { // Contains if (searchValue.IsBmp) { Assert.Equal(expectedIndex >= 0, utf8String.Contains((char)searchValue.Value)); } Assert.Equal(expectedIndex >= 0, utf8String.Contains(searchValue)); // IndexOf if (searchValue.IsBmp) { Assert.Equal(expectedIndex, utf8String.IndexOf((char)searchValue.Value)); } Assert.Equal(expectedIndex, utf8String.IndexOf(searchValue)); }
public void IndexOfNonOccuringSingleCodePointConstructFromByteArray(int length, int minCodePoint, int maxCodePoint, string description, bool useInnerLoop = false) { string s = GetRandomString(length, minCodePoint, maxCodePoint); Utf8String utf8s = new Utf8String(s); utf8s = new Utf8String(utf8s.CopyBytes()); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { for (int i = 0; i < (useInnerLoop ? Benchmark.InnerIterationCount : 1); i++) { int p = utf8s.IndexOf(31); } } } }
public unsafe void IndexOfNonOccuringSingleCodeUnitConstructFromSpan(int length, int minCodePoint, int maxCodePoint, string description, bool useInnerLoop = false) { string s = GetRandomString(length, minCodePoint, maxCodePoint); Utf8String utf8s = new Utf8String(s); fixed(byte *bytes = utf8s.CopyBytes()) { utf8s = new Utf8String(new Span <byte>(bytes, utf8s.Length)); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { for (int i = 0; i < (useInnerLoop ? Benchmark.InnerIterationCount : 1); i++) { int p = utf8s.IndexOf((byte)31); } } } } }
public void IndexOfNonOccuringSingleCodeUnitConstructFromByteArray() { TestCase[] testCases = new TestCase[] { new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 30000000), new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 30000000), new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 3000), new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 3000) }; foreach (TestCase testData in testCases) { string s = testData.String; Utf8String utf8s = new Utf8String(s); utf8s = new Utf8String(utf8s.CopyBytes()); int iterations = testData.Iterations; _timer.Restart(); while (iterations-- != 0) { int p = utf8s.IndexOf((byte)31); } PrintTime(testData); } }
public void IndexOfUtf8CharacterTest(string s, char character) { int expected = s.IndexOf(character); Utf8String u8s = new Utf8String(s); Utf8CodeUnit u8codeUnit = (Utf8CodeUnit)(byte)(character); Assert.Equal(expected, u8s.IndexOf(u8codeUnit)); }
public unsafe void IndexOfNonOccuringSingleCodePointConstructFromSpan() { TestCase[] testCases = new TestCase[] { new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 5000000), new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 5000000), new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 500), new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 500) }; foreach (TestCase testData in testCases) { string s = testData.String; Utf8String utf8s = new Utf8String(s); fixed (byte* bytes = utf8s.CopyBytes()) { utf8s = new Utf8String(new Span<byte>(bytes, utf8s.Length)); int iterations = testData.Iterations; _timer.Restart(); while (iterations-- != 0) { int p = utf8s.IndexOf((UnicodeCodePoint)31); } PrintTime(testData); } } }
public unsafe void IndexOfNonOccuringSingleCodeUnitConstructFromSpan() { foreach (StringWithDescription testData in StringsWithDescription()) { string s = testData.String; Utf8String utf8s = new Utf8String(s); fixed (byte* bytes = utf8s.CopyBytes()) { utf8s = new Utf8String(new ByteSpan(bytes, utf8s.Length)); int iterations = testData.Iterations; _timer.Restart(); while (iterations-- != 0) { int p = utf8s.IndexOf((Utf8CodeUnit)31); } PrintTime(testData); } } }
public void IndexOfNonOccuringSingleCodeUnitConstructFromByteArray() { foreach (StringWithDescription testData in StringsWithDescription()) { string s = testData.String; Utf8String utf8s = new Utf8String(s); utf8s = new Utf8String(utf8s.CopyBytes()); int iterations = testData.Iterations; _timer.Restart(); while (iterations-- != 0) { int p = utf8s.IndexOf((Utf8CodeUnit)31); } PrintTime(testData); } }