File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -53,11 +53,7 @@ public static string ReplaceInvalidFileNameChars(this string value)
53
53
{
54
54
var span = value . AsSpan ( ) ;
55
55
56
- #if NET8_0_OR_GREATER
57
- var index = span . IndexOfAny ( invalidFileNameSearchValues ) ;
58
- #else
59
- var index = span . IndexOfAny ( invalidFileNameChars . AsSpan ( ) ) ;
60
- #endif
56
+ var index = IndexOfInvalidChar ( span ) ;
61
57
62
58
if ( index == - 1 )
63
59
{
@@ -80,6 +76,14 @@ public static string ReplaceInvalidFileNameChars(this string value)
80
76
return new ( chars ) ;
81
77
}
82
78
79
+ static int IndexOfInvalidChar ( CharSpan span ) =>
80
+ #if NET8_0_OR_GREATER
81
+ span . IndexOfAny ( invalidFileNameSearchValues ) ;
82
+ #else
83
+ span . IndexOfAny ( invalidFileNameChars . AsSpan ( ) ) ;
84
+ #endif
85
+
86
+
83
87
static bool IsInvalid ( char ch ) =>
84
88
#if NET8_0_OR_GREATER
85
89
invalidFileNameSearchValues . Contains ( ch ) ;
@@ -89,6 +93,15 @@ static bool IsInvalid(char ch) =>
89
93
90
94
public static void AppendValid ( StringBuilder builder , string value )
91
95
{
96
+ var span = value . AsSpan ( ) ;
97
+ var index = IndexOfInvalidChar ( span ) ;
98
+
99
+ if ( index == - 1 )
100
+ {
101
+ builder . Append ( value ) ;
102
+ return ;
103
+ }
104
+
92
105
foreach ( var ch in value )
93
106
{
94
107
if ( IsInvalid ( ch ) )
You can’t perform that action at this time.
0 commit comments