diff options
| author | Cody Robibero <cody@robibe.ro> | 2021-08-04 06:24:58 -0600 |
|---|---|---|
| committer | Cody Robibero <cody@robibe.ro> | 2021-08-04 06:24:58 -0600 |
| commit | 398ca85944c21609156892dd8c5560126336f11b (patch) | |
| tree | 5ccd6d959a64a262e1db4a1583619e30775edb68 /src/Jellyfin.Extensions/StringExtensions.cs | |
| parent | d212b6fb08fc8d45008499f3dfce33f59bb425e3 (diff) | |
| parent | 1b8eb1aefe2a10b9671e801e8b1feeb8e2362c87 (diff) | |
Merge remote-tracking branch 'upstream/master' into baseitemkind-fixes
Diffstat (limited to 'src/Jellyfin.Extensions/StringExtensions.cs')
| -rw-r--r-- | src/Jellyfin.Extensions/StringExtensions.cs | 31 |
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; + } + } +} |
