Skip to content

Commit 846f3c9

Browse files
authored
Merge branch 'main' into dependabot/nuget/Microsoft.AspNetCore.WebUtilities-8.0.14
2 parents f9df013 + cf67ca9 commit 846f3c9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/idunno.AtProto/InternalStringExtensions.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,32 @@ public static bool IsOnlyAsciiLetters(this string s)
6767

6868
return true;
6969
}
70+
71+
/// <summary>
72+
/// Gets a flag indicating whether the string only consists of ASCII letters and numbers.
73+
/// </summary>
74+
/// <param name="s">The string to check.</param>
75+
/// <returns>True if the string only consists of ASCII letters, otherwise false.</returns>
76+
public static bool IsOnlyAsciiLettersAndNumbers(this string s)
77+
{
78+
if (string.IsNullOrEmpty(s))
79+
{
80+
return true;
81+
}
82+
83+
foreach (char item in s)
84+
{
85+
if (item is >= 'A' and <= 'Z' or >= 'a' and <= 'z' or >= '0' and <= '9')
86+
{
87+
continue;
88+
}
89+
else
90+
{
91+
return false;
92+
}
93+
}
94+
95+
return true;
96+
}
7097
}
7198
}

test/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<Using Include="System.Diagnostics.CodeAnalysis" />
910
<Using Include="Xunit" />
1011
</ItemGroup>
1112

0 commit comments

Comments
 (0)