mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-04-30 10:50:09 +00:00
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System;
|
|
|
|
namespace SabreTools.Text.Extensions
|
|
{
|
|
public static class StringExtensions
|
|
{
|
|
#region Optional Extensions
|
|
|
|
/// <inheritdoc cref="string.Contains(string)"/>
|
|
public static bool OptionalContains(this string? self, string value)
|
|
=> OptionalContains(self, value, StringComparison.Ordinal);
|
|
|
|
/// <inheritdoc cref="string.Contains(string, StringComparison)"/>
|
|
public static bool OptionalContains(this string? self, string value, StringComparison comparisonType)
|
|
{
|
|
if (self is null)
|
|
return false;
|
|
|
|
#if NETFRAMEWORK || NETSTANDARD2_0
|
|
return self.Contains(value);
|
|
#else
|
|
return self.Contains(value, comparisonType);
|
|
#endif
|
|
}
|
|
|
|
/// <inheritdoc cref="string.EndsWith(string)"/>
|
|
public static bool OptionalEndsWith(this string? self, string value)
|
|
=> OptionalEndsWith(self, value, StringComparison.Ordinal);
|
|
|
|
/// <inheritdoc cref="string.EndsWith(string, StringComparison)"/>
|
|
public static bool OptionalEndsWith(this string? self, string value, StringComparison comparisonType)
|
|
{
|
|
if (self is null)
|
|
return false;
|
|
|
|
return self.EndsWith(value, comparisonType);
|
|
}
|
|
|
|
/// <inheritdoc cref="string.Equals(string)"/>
|
|
public static bool OptionalEquals(this string? self, string value)
|
|
=> OptionalEquals(self, value, StringComparison.Ordinal);
|
|
|
|
/// <inheritdoc cref="string.Equals(string, StringComparison)"/>
|
|
public static bool OptionalEquals(this string? self, string value, StringComparison comparisonType)
|
|
{
|
|
if (self is null)
|
|
return false;
|
|
|
|
return self.Equals(value, comparisonType);
|
|
}
|
|
|
|
/// <inheritdoc cref="string.StartsWith(string)"/>
|
|
public static bool OptionalStartsWith(this string? self, string value)
|
|
=> OptionalStartsWith(self, value, StringComparison.Ordinal);
|
|
|
|
/// <inheritdoc cref="string.StartsWith(string, StringComparison)"/>
|
|
public static bool OptionalStartsWith(this string? self, string value, StringComparison comparisonType)
|
|
{
|
|
if (self is null)
|
|
return false;
|
|
|
|
return self.StartsWith(value, comparisonType);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|