aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Extensions/StringExtensions.cs
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2021-06-19 18:02:33 +0200
committerBond_009 <bond.009@outlook.com>2021-06-19 18:04:46 +0200
commit6f8ccab788e85e025eaa44b67a1487bf419afb53 (patch)
treef8895fae8ec17e922daab473180c9de9a702a02a /src/Jellyfin.Extensions/StringExtensions.cs
parent0c3dcdf77b0d124517bffa608bfddf7d8f7682db (diff)
Move non-jellyfin extensions to separate project
Diffstat (limited to 'src/Jellyfin.Extensions/StringExtensions.cs')
-rw-r--r--src/Jellyfin.Extensions/StringExtensions.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Jellyfin.Extensions/StringExtensions.cs b/src/Jellyfin.Extensions/StringExtensions.cs
new file mode 100644
index 000000000..acc695ed2
--- /dev/null
+++ b/src/Jellyfin.Extensions/StringExtensions.cs
@@ -0,0 +1,31 @@
+using System;
+
+namespace Jellyfin.Extensions
+{
+ /// <summary>
+ /// Provides extensions methods for <see cref="string" />.
+ /// </summary>
+ public static class StringExtensions
+ {
+ /// <summary>
+ /// Counts the number of occurrences of [needle] in the string.
+ /// </summary>
+ /// <param name="value">The haystack to search in.</param>
+ /// <param name="needle">The character to search for.</param>
+ /// <returns>The number of occurrences of the [needle] character.</returns>
+ public static int Count(this ReadOnlySpan<char> value, char needle)
+ {
+ var count = 0;
+ var length = value.Length;
+ for (var i = 0; i < length; i++)
+ {
+ if (value[i] == needle)
+ {
+ count++;
+ }
+ }
+
+ return count;
+ }
+ }
+}