delete HowMany() extension method and just use .Count() instead, the one value add of null/empty checking was never utilized anyway
This commit is contained in:
parent
96b0b37673
commit
6d7d36c1d0
|
@ -400,7 +400,7 @@ namespace BizHawk.Client.Common
|
|||
continue;
|
||||
}
|
||||
|
||||
var numColumns = line.HowMany('\t');
|
||||
var numColumns = line.Count(c => c == '\t');
|
||||
int startIndex;
|
||||
if (numColumns == 5)
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace BizHawk.Common.StringExtensions
|
|||
/// This method returning <see langword="true"/> for some <paramref name="str"/> does not imply that <see cref="float.TryParse(string,out float)">float.TryParse</see> will also return <see langword="true"/>.<br/>
|
||||
/// Also this has nothing to do with fixed- vs. floating-point numbers, a better name would be <c>IsUnsignedDecimal</c>.
|
||||
/// </remarks>
|
||||
public static bool IsFixedPoint(this string? str) => !string.IsNullOrWhiteSpace(str) && str.HowMany('.') <= 1 && str.All(IsFixedPoint);
|
||||
public static bool IsFixedPoint(this string? str) => !string.IsNullOrWhiteSpace(str) && str.Count(c => c == '.') <= 1 && str.All(IsFixedPoint);
|
||||
|
||||
/// <returns><see langword="true"/> iff <paramref name="c"/> is <c>'-'</c>, <c>'.'</c>, or a digit</returns>
|
||||
/// <remarks>Also this has nothing to do with fixed- vs. floating-point numbers, a better name would be <c>IsSignedDecimal</c>.</remarks>
|
||||
|
@ -80,7 +80,7 @@ namespace BizHawk.Common.StringExtensions
|
|||
/// This method returning <see langword="true"/> for some <paramref name="str"/> does not imply that <see cref="float.TryParse(string,out float)">float.TryParse</see> will also return <see langword="true"/>.<br/>
|
||||
/// Also this has nothing to do with fixed- vs. floating-point numbers, a better name would be <c>IsSignedDecimal</c>.
|
||||
/// </remarks>
|
||||
public static bool IsFloat(this string? str) => !string.IsNullOrWhiteSpace(str) && str.HowMany('.') <= 1 && str[0].IsFloat() && str.Substring(1).All(IsFixedPoint);
|
||||
public static bool IsFloat(this string? str) => !string.IsNullOrWhiteSpace(str) && str.Count(c => c == '.') <= 1 && str[0].IsFloat() && str.Substring(1).All(IsFixedPoint);
|
||||
|
||||
/// <returns>
|
||||
/// <see langword="true"/> iff <paramref name="str"/> is not <see langword="null"/>,
|
||||
|
|
|
@ -5,9 +5,6 @@ namespace BizHawk.Common.StringExtensions
|
|||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <returns>how many times <paramref name="c"/> appears in <paramref name="str"/>, or <c>0</c> if <paramref name="str"/> is null</returns>
|
||||
public static int HowMany(this string? str, char c) => string.IsNullOrEmpty(str) ? 0 : str.Count(t => t == c);
|
||||
|
||||
/// <returns><see langword="true"/> if <paramref name="str"/> appears in <paramref name="options"/> (case-insensitive)</returns>
|
||||
public static bool In(this string str, params string[] options) => options.Any(opt => string.Equals(opt, str, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue