Merge pull request #2920 from Bond-009/tests2

Add some simple tests
This commit is contained in:
Vasily
2020-04-29 12:17:01 +03:00
committed by GitHub
19 changed files with 173 additions and 60 deletions

View File

@@ -1,3 +1,5 @@
#nullable enable
using System;
using System.Security.Cryptography;
using System.Text;

View File

@@ -1,3 +1,5 @@
#nullable enable
using System.Collections.Generic;
namespace MediaBrowser.Common.Extensions

View File

@@ -1,3 +1,5 @@
#nullable enable
using System;
namespace MediaBrowser.Common.Extensions

View File

@@ -1,3 +1,5 @@
#nullable enable
using System;
using System.Diagnostics;
using System.Threading;

View File

@@ -1,3 +1,4 @@
#nullable enable
#pragma warning disable CS1591
using System;

View File

@@ -1,3 +1,5 @@
#nullable enable
using System;
namespace MediaBrowser.Common.Extensions

View File

@@ -0,0 +1,37 @@
#nullable enable
using System;
namespace MediaBrowser.Common.Extensions
{
/// <summary>
/// Extensions methods to simplify string operations.
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Returns the part on the left of the <c>needle</c>.
/// </summary>
/// <param name="haystack">The string to seek.</param>
/// <param name="needle">The needle to find.</param>
/// <returns>The part left of the <paramref name="needle" />.</returns>
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, char needle)
{
var pos = haystack.IndexOf(needle);
return pos == -1 ? haystack : haystack[..pos];
}
/// <summary>
/// Returns the part on the left of the <c>needle</c>.
/// </summary>
/// <param name="haystack">The string to seek.</param>
/// <param name="needle">The needle to find.</param>
/// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</param>
/// <returns>The part left of the <c>needle</c>.</returns>
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, ReadOnlySpan<char> needle, StringComparison stringComparison = default)
{
var pos = haystack.IndexOf(needle, stringComparison);
return pos == -1 ? haystack : haystack[..pos];
}
}
}