Skip to content

Commit 8994617

Browse files
authored
Add SearchValues<string> (#88394)
* Add SearchValues<string>
1 parent ac02b66 commit 8994617

37 files changed

+4372
-94
lines changed

THIRD-PARTY-NOTICES.TXT

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,3 +1270,30 @@ Licensed under the Apache License, Version 2.0.
12701270

12711271
Available at
12721272
https://github.com/SixLabors/ImageSharp/blob/f4f689ce67ecbcc35cebddba5aacb603e6d1068a/LICENSE
1273+
1274+
License for the Teddy multi-substring searching implementation
1275+
--------------------------------------
1276+
1277+
https://github.com/BurntSushi/aho-corasick
1278+
1279+
The MIT License (MIT)
1280+
1281+
Copyright (c) 2015 Andrew Gallant
1282+
1283+
Permission is hereby granted, free of charge, to any person obtaining a copy
1284+
of this software and associated documentation files (the "Software"), to deal
1285+
in the Software without restriction, including without limitation the rights
1286+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1287+
copies of the Software, and to permit persons to whom the Software is
1288+
furnished to do so, subject to the following conditions:
1289+
1290+
The above copyright notice and this permission notice shall be included in
1291+
all copies or substantial portions of the Software.
1292+
1293+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1294+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1295+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1296+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1297+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1298+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1299+
THE SOFTWARE.

src/libraries/System.Memory/ref/System.Memory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ public static partial class MemoryExtensions
235235
public static bool Contains(this System.ReadOnlySpan<char> span, System.ReadOnlySpan<char> value, System.StringComparison comparisonType) { throw null; }
236236
public static bool Contains<T>(this System.ReadOnlySpan<T> span, T value) where T : System.IEquatable<T>? { throw null; }
237237
public static bool Contains<T>(this System.Span<T> span, T value) where T : System.IEquatable<T>? { throw null; }
238+
public static bool ContainsAny(this System.ReadOnlySpan<char> span, System.Buffers.SearchValues<string> values) { throw null; }
239+
public static bool ContainsAny(this System.Span<char> span, System.Buffers.SearchValues<string> values) { throw null; }
238240
public static bool ContainsAny<T>(this System.ReadOnlySpan<T> span, System.Buffers.SearchValues<T> values) where T : System.IEquatable<T>? { throw null; }
239241
public static bool ContainsAny<T>(this System.ReadOnlySpan<T> span, System.ReadOnlySpan<T> values) where T : System.IEquatable<T>? { throw null; }
240242
public static bool ContainsAny<T>(this System.ReadOnlySpan<T> span, T value0, T value1) where T : System.IEquatable<T>? { throw null; }
@@ -272,6 +274,8 @@ public static void CopyTo<T>(this T[]? source, System.Span<T> destination) { }
272274
public static System.Text.SpanRuneEnumerator EnumerateRunes(this System.Span<char> span) { throw null; }
273275
public static bool Equals(this System.ReadOnlySpan<char> span, System.ReadOnlySpan<char> other, System.StringComparison comparisonType) { throw null; }
274276
public static int IndexOf(this System.ReadOnlySpan<char> span, System.ReadOnlySpan<char> value, System.StringComparison comparisonType) { throw null; }
277+
public static int IndexOfAny(this System.ReadOnlySpan<char> span, System.Buffers.SearchValues<string> values) { throw null; }
278+
public static int IndexOfAny(this System.Span<char> span, System.Buffers.SearchValues<string> values) { throw null; }
275279
public static int IndexOfAny<T>(this System.ReadOnlySpan<T> span, System.Buffers.SearchValues<T> values) where T : System.IEquatable<T>? { throw null; }
276280
public static int IndexOfAny<T>(this System.ReadOnlySpan<T> span, System.ReadOnlySpan<T> values) where T : System.IEquatable<T>? { throw null; }
277281
public static int IndexOfAny<T>(this System.ReadOnlySpan<T> span, T value0, T value1) where T : System.IEquatable<T>? { throw null; }

src/libraries/System.Memory/tests/Span/StringSearchValues.cs

Lines changed: 519 additions & 0 deletions
Large diffs are not rendered by default.

src/libraries/System.Memory/tests/System.Memory.Tests.csproj

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
<Compile Include="MemoryMarshal\CreateSpan.cs" />
1919
<Compile Include="MemoryMarshal\CreateReadOnlySpan.cs" />
2020
<Compile Include="MemoryMarshal\CreateReadOnlySpanFromNullTerminated.cs" />
21-
<Compile Include="$(CommonPath)..\tests\System\RealFormatterTestsBase.cs"
22-
Link="ParsersAndFormatters\Formatter\RealFormatterTestsBase.cs" />
21+
<Compile Include="$(CommonPath)..\tests\System\RealFormatterTestsBase.cs" Link="ParsersAndFormatters\Formatter\RealFormatterTestsBase.cs" />
2322
<Compile Include="ParsersAndFormatters\Formatter\RealFormatterTests.cs" />
24-
<Compile Include="$(CommonPath)..\tests\System\RealParserTestsBase.cs"
25-
Link="ParsersAndFormatters\Parser\RealParserTestsBase.cs" />
23+
<Compile Include="$(CommonPath)..\tests\System\RealParserTestsBase.cs" Link="ParsersAndFormatters\Parser\RealParserTestsBase.cs" />
2624
<Compile Include="ParsersAndFormatters\Parser\RealParserTests.cs" />
2725
<Compile Include="ReadOnlySpan\Contains.byte.cs" />
2826
<Compile Include="ReadOnlySpan\Contains.T.cs" />
27+
<Compile Include="Span\StringSearchValues.cs" />
2928
<Compile Include="Span\Reflection.cs" />
3029
<Compile Include="SequenceReader\Advance.cs" />
3130
<Compile Include="SequenceReader\BasicTests.cs" />
@@ -276,9 +275,7 @@
276275
<Compile Include="Base64\Base64ValidationUnitTests.cs" />
277276
</ItemGroup>
278277
<ItemGroup>
279-
<Compile Include="$(CommonTestPath)System\Buffers\NativeMemoryManager.cs"
280-
Link="Common\System\Buffers\NativeMemoryManager.cs" />
281-
<Compile Include="$(CommonPath)System\MutableDecimal.cs"
282-
Link="Common\System\MutableDecimal.cs" />
278+
<Compile Include="$(CommonTestPath)System\Buffers\NativeMemoryManager.cs" Link="Common\System\Buffers\NativeMemoryManager.cs" />
279+
<Compile Include="$(CommonPath)System\MutableDecimal.cs" Link="Common\System\MutableDecimal.cs" />
283280
</ItemGroup>
284281
</Project>

src/libraries/System.Private.CoreLib/src/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,4 +4250,7 @@
42504250
<data name="OutOfMemory_StringTooLong" xml:space="preserve">
42514251
<value>String length exceeded supported range.</value>
42524252
</data>
4253+
<data name="Argument_SearchValues_UnsupportedStringComparison" xml:space="preserve">
4254+
<value>SearchValues&lt;string&gt; supports only StringComparison.Ordinal and StringComparison.OrdinalIgnoreCase.</value>
4255+
</data>
42534256
</root>

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,27 @@
440440
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\SearchValuesDebugView.cs" />
441441
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\EmptySearchValues.cs" />
442442
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\ProbabilisticMap.cs" />
443+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\AhoCorasick.cs" />
444+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\AhoCorasickBuilder.cs" />
445+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\AhoCorasickNode.cs" />
446+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\CharacterFrequencyHelper.cs" />
447+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\EightPackedReferences.cs" />
448+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\RabinKarp.cs" />
449+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\StringSearchValuesHelper.cs" />
450+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\TeddyBucketizer.cs" />
451+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\Helpers\TeddyHelper.cs" />
452+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\AsciiStringSearchValuesTeddyBucketizedN2.cs" />
453+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\AsciiStringSearchValuesTeddyBucketizedN3.cs" />
454+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\AsciiStringSearchValuesTeddyNonBucketizedN2.cs" />
455+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\AsciiStringSearchValuesTeddyNonBucketizedN3.cs" />
456+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\AsciiStringSearchValuesTeddyBase.cs" />
457+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\MultiStringIgnoreCaseSearchValuesFallback.cs" />
458+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\SingleStringSearchValuesThreeChars.cs" />
459+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\SingleStringSearchValuesFallback.cs" />
460+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\StringSearchValues.cs" />
461+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\StringSearchValuesBase.cs" />
462+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\StringSearchValuesAhoCorasick.cs" />
463+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Strings\StringSearchValuesRabinKarp.cs" />
443464
<Compile Include="$(MSBuildThisFileDirectory)System\IndexOutOfRangeException.cs" />
444465
<Compile Include="$(MSBuildThisFileDirectory)System\InsufficientExecutionStackException.cs" />
445466
<Compile Include="$(MSBuildThisFileDirectory)System\InsufficientMemoryException.cs" />

src/libraries/System.Private.CoreLib/src/System/Globalization/SurrogateCasing.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal static void ToUpper(char h, char l, out char hr, out char lr)
1616
Debug.Assert(char.IsLowSurrogate(l));
1717

1818
UnicodeUtility.GetUtf16SurrogatesFromSupplementaryPlaneScalar(CharUnicodeInfo.ToUpper(UnicodeUtility.GetScalarFromUtf16SurrogatePair(h, l)), out hr, out lr);
19+
20+
Debug.Assert(char.IsHighSurrogate(hr));
21+
Debug.Assert(char.IsLowSurrogate(lr));
1922
}
2023

2124
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -25,6 +28,9 @@ internal static void ToLower(char h, char l, out char hr, out char lr)
2528
Debug.Assert(char.IsLowSurrogate(l));
2629

2730
UnicodeUtility.GetUtf16SurrogatesFromSupplementaryPlaneScalar(CharUnicodeInfo.ToLower(UnicodeUtility.GetScalarFromUtf16SurrogatePair(h, l)), out hr, out lr);
31+
32+
Debug.Assert(char.IsHighSurrogate(hr));
33+
Debug.Assert(char.IsLowSurrogate(lr));
2834
}
2935

3036
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,24 @@ private unsafe char ChangeCase(char c, bool toUpper)
190190
return dst;
191191
}
192192

193+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
194+
internal static char ToUpperOrdinal(char c)
195+
{
196+
if (GlobalizationMode.Invariant)
197+
{
198+
return InvariantModeCasing.ToUpper(c);
199+
}
200+
201+
if (GlobalizationMode.UseNls)
202+
{
203+
return char.IsAscii(c)
204+
? ToUpperAsciiInvariant(c)
205+
: Invariant.ChangeCase(c, toUpper: true);
206+
}
207+
208+
return OrdinalCasing.ToUpper(c);
209+
}
210+
193211
[MethodImpl(MethodImplOptions.AggressiveInlining)]
194212
internal void ChangeCaseToLower(ReadOnlySpan<char> source, Span<char> destination)
195213
{
@@ -436,7 +454,7 @@ public string ToUpper(string str)
436454
}
437455

438456
[MethodImpl(MethodImplOptions.AggressiveInlining)]
439-
private static char ToUpperAsciiInvariant(char c)
457+
internal static char ToUpperAsciiInvariant(char c)
440458
{
441459
if (char.IsAsciiLetterLower(c))
442460
{

0 commit comments

Comments
 (0)