using System;
namespace SabreTools.Text.Extensions
{
public static class StringExtensions
{
#region Optional Extensions
///
public static bool OptionalContains(this string? self, string value)
=> OptionalContains(self, value, StringComparison.Ordinal);
///
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
}
///
public static bool OptionalEndsWith(this string? self, string value)
=> OptionalEndsWith(self, value, StringComparison.Ordinal);
///
public static bool OptionalEndsWith(this string? self, string value, StringComparison comparisonType)
{
if (self is null)
return false;
return self.EndsWith(value, comparisonType);
}
///
public static bool OptionalEquals(this string? self, string value)
=> OptionalEquals(self, value, StringComparison.Ordinal);
///
public static bool OptionalEquals(this string? self, string value, StringComparison comparisonType)
{
if (self is null)
return false;
return self.Equals(value, comparisonType);
}
///
public static bool OptionalStartsWith(this string? self, string value)
=> OptionalStartsWith(self, value, StringComparison.Ordinal);
///
public static bool OptionalStartsWith(this string? self, string value, StringComparison comparisonType)
{
if (self is null)
return false;
return self.StartsWith(value, comparisonType);
}
#endregion
}
}