|
3 | 3 |
|
4 | 4 | #nullable enable |
5 | 5 |
|
| 6 | +using System.Buffers; |
6 | 7 | using System.Collections.Immutable; |
7 | 8 | using System.Diagnostics; |
8 | 9 | using System.Security; |
@@ -814,9 +815,11 @@ public static CSharpDirective Parse(SourceFile sourceFile, TextSpan span, string |
814 | 815 | }; |
815 | 816 | } |
816 | 817 |
|
817 | | - private static (string, string?) ParseOptionalTwoParts(SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText) |
| 818 | + private static (string, string?) ParseOptionalTwoParts(SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText, SearchValues<char>? separators = null) |
818 | 819 | { |
819 | | - var i = directiveText.IndexOf(' ', StringComparison.Ordinal); |
| 820 | + var i = separators != null |
| 821 | + ? directiveText.AsSpan().IndexOfAny(separators) |
| 822 | + : directiveText.IndexOf(' ', StringComparison.Ordinal); |
820 | 823 | var firstPart = checkFirstPart(i < 0 ? directiveText : directiveText[..i]); |
821 | 824 | var secondPart = i < 0 ? [] : directiveText.AsSpan((i + 1)..).TrimStart(); |
822 | 825 | if (i < 0 || secondPart.IsWhiteSpace()) |
@@ -912,14 +915,16 @@ private Property() { } |
912 | 915 | /// </summary> |
913 | 916 | public sealed class Package : CSharpDirective |
914 | 917 | { |
| 918 | + private static readonly SearchValues<char> s_separators = SearchValues.Create(' ', '@'); |
| 919 | + |
915 | 920 | private Package() { } |
916 | 921 |
|
917 | 922 | public required string Name { get; init; } |
918 | 923 | public string? Version { get; init; } |
919 | 924 |
|
920 | 925 | public static new Package Parse(SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText) |
921 | 926 | { |
922 | | - var (packageName, packageVersion) = ParseOptionalTwoParts(sourceFile, span, directiveKind, directiveText); |
| 927 | + var (packageName, packageVersion) = ParseOptionalTwoParts(sourceFile, span, directiveKind, directiveText, s_separators); |
923 | 928 |
|
924 | 929 | return new Package |
925 | 930 | { |
|
0 commit comments