Skip to content

Commit

Permalink
Merge pull request #54 from Tynab/develop
Browse files Browse the repository at this point in the history
v3.2.2
  • Loading branch information
Tynab authored Dec 3, 2023
2 parents 481e041 + dcfa87e commit f6d8718
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 76 deletions.
22 changes: 4 additions & 18 deletions lib/YANLib/YANLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,13 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>Update
- Bool
- Model
- Num
- Decimal
- Double
- Float
- Int
- Long
- Nint
- Nuint
- Sbyte
- Short
- Uint
- Ulong
- Ushort
- Pass
- Random</PackageReleaseNotes>
- Text
- Char
- String</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageId>Tynab.YANLib</PackageId>
<Version>3.2.1</Version>
<Version>3.2.2</Version>
<LangVersion>preview</LangVersion>
</PropertyGroup>

Expand Down
10 changes: 5 additions & 5 deletions lib/YANLib/YANText.Char.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public static partial class YANText

public static bool AnyWhiteSpace(this IEnumerable<char> cs) => cs is not null && cs.Any(c => c.IsWhiteSpace());

public static bool IsWhiteSpaceOrNull(this char c) => c.IsEmpty() || c.IsWhiteSpace();
public static bool IsWhiteSpaceOrEmpty(this char c) => c.IsEmpty() || c.IsWhiteSpace();

public static bool AllWhiteSpaceOrNull(params char[] cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace());

public static bool AnyWhiteSpaceOrNull(params char[] cs) => cs is not null && cs.Any(c => c.IsWhiteSpaceOrNull());
public static bool AnyWhiteSpaceOrNull(params char[] cs) => cs is not null && cs.Any(c => c.IsWhiteSpaceOrEmpty());

public static bool AllWhiteSpaceOrNull(this IEnumerable<char> cs) => cs is not null && !cs.Any(c => c.IsNotEmptyAndWhiteSpace());

public static bool AnyWhiteSpaceOrNull(this IEnumerable<char> cs) => cs is not null && cs.Any(c => c.IsWhiteSpaceOrNull());
public static bool AnyWhiteSpaceOrNull(this IEnumerable<char> cs) => cs is not null && cs.Any(c => c.IsWhiteSpaceOrEmpty());

public static bool IsAlphabetic(this char c) => char.IsLetter(c);

Expand Down Expand Up @@ -97,11 +97,11 @@ public static partial class YANText

public static bool IsNotEmptyAndWhiteSpace(this char c) => c.IsNotEmpty() && c.IsNotWhiteSpace();

public static bool AllNotEmptyAndWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsWhiteSpaceOrNull());
public static bool AllNotEmptyAndWhiteSpace(params char[] cs) => cs is not null && !cs.Any(c => c.IsWhiteSpaceOrEmpty());

public static bool AnyNotEmptyAndWhiteSpace(params char[] cs) => cs is not null && cs.Any(c => c.IsNotEmptyAndWhiteSpace());

public static bool AllNotEmptyAndWhiteSpace(this IEnumerable<char> cs) => cs is not null && !cs.Any(c => c.IsWhiteSpaceOrNull());
public static bool AllNotEmptyAndWhiteSpace(this IEnumerable<char> cs) => cs is not null && !cs.Any(c => c.IsWhiteSpaceOrEmpty());

public static bool AnyNotEmptyAndWhiteSpace(this IEnumerable<char> cs) => cs is not null && cs.Any(c => c.IsNotEmptyAndWhiteSpace());

Expand Down
106 changes: 53 additions & 53 deletions lib/YANLib/YANText.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,86 @@ namespace YANLib;
public static partial class YANText
{

public static bool IsNull([NotNullWhen(false)] this string str) => str is null;
public static bool IsNull([NotNullWhen(false)] this string? str) => str is null;

public static bool AllNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotNull());
public static bool AllNull(params string?[] strs) => strs is not null && !strs.Any(s => s.IsNotNull());

public static bool AnyNull(params string[] strs) => strs is not null && strs.Any(s => s.IsNull());
public static bool AnyNull(params string?[] strs) => strs is not null && strs.Any(s => s.IsNull());

public static bool AllNull(this IEnumerable<string> strs) => strs is not null && !strs.Any(s => s.IsNotNull());
public static bool AllNull(this IEnumerable<string?> strs) => strs is not null && !strs.Any(s => s.IsNotNull());

public static bool AnyNull(this IEnumerable<string> strs) => strs is not null && strs.Any(s => s.IsNull());
public static bool AnyNull(this IEnumerable<string?> strs) => strs is not null && strs.Any(s => s.IsNull());

public static bool IsEmptyOrNull([NotNullWhen(false)] this string str) => string.IsNullOrEmpty(str);
public static bool IsEmptyOrNull([NotNullWhen(false)] this string? str) => string.IsNullOrEmpty(str);

public static bool AllEmptyOrNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotEmptyAndNull());
public static bool AllEmptyOrNull(params string?[] strs) => strs is not null && !strs.Any(s => s.IsNotEmptyAndNull());

public static bool AnyEmptyOrNull(params string[] strs) => strs is not null && strs.Any(s => s.IsEmptyOrNull());
public static bool AnyEmptyOrNull(params string?[] strs) => strs is not null && strs.Any(s => s.IsEmptyOrNull());

public static bool AllEmptyOrNull(this IEnumerable<string> strs) => strs is not null && !strs.Any(s => s.IsNotEmptyAndNull());
public static bool AllEmptyOrNull(this IEnumerable<string?> strs) => strs is not null && !strs.Any(s => s.IsNotEmptyAndNull());

public static bool AnyEmptyOrNull(this IEnumerable<string> strs) => strs is not null && strs.Any(s => s.IsEmptyOrNull());
public static bool AnyEmptyOrNull(this IEnumerable<string?> strs) => strs is not null && strs.Any(s => s.IsEmptyOrNull());

public static bool IsWhiteSpaceOrNull([NotNullWhen(false)] this string str) => string.IsNullOrWhiteSpace(str);
public static bool IsWhiteSpaceOrNull([NotNullWhen(false)] this string? str) => string.IsNullOrWhiteSpace(str);

public static bool AllWhiteSpaceOrNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNotWhiteSpaceAndNull());
public static bool AllWhiteSpaceOrNull(params string?[] strs) => strs is not null && !strs.Any(s => s.IsNotWhiteSpaceAndNull());

public static bool AnyWhiteSpaceOrNull(params string[] strs) => strs is not null && strs.Any(s => s.IsWhiteSpaceOrNull());
public static bool AnyWhiteSpaceOrNull(params string?[] strs) => strs is not null && strs.Any(s => s.IsWhiteSpaceOrNull());

public static bool AllWhiteSpaceOrNull(this IEnumerable<string> strs) => strs is not null && !strs.Any(s => s.IsNotWhiteSpaceAndNull());
public static bool AllWhiteSpaceOrNull(this IEnumerable<string?> strs) => strs is not null && !strs.Any(s => s.IsNotWhiteSpaceAndNull());

public static bool AnyWhiteSpaceOrNull(this IEnumerable<string> strs) => strs is not null && strs.Any(s => s.IsWhiteSpaceOrNull());
public static bool AnyWhiteSpaceOrNull(this IEnumerable<string?> strs) => strs is not null && strs.Any(s => s.IsWhiteSpaceOrNull());

public static bool EqualsIgnoreCase(this string str1, string str2) => AllNull(str1, str2) || str1.IsNotNull() && str1.IsNotNull() && string.Equals(str1, str2, OrdinalIgnoreCase);
public static bool EqualsIgnoreCase(this string? str1, string? str2) => AllNull(str1, str2) || str1.IsNotNull() && str1.IsNotNull() && string.Equals(str1, str2, OrdinalIgnoreCase);

public static bool AllEqualsIgnoreCase(params string[] strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs[0]));
public static bool AllEqualsIgnoreCase(params string?[] strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs[0]));

public static bool AnyEqualsIgnoreCase(params string[] strs) => !strs.AllNotEqualsIgnoreCase();
public static bool AnyEqualsIgnoreCase(params string?[] strs) => !strs.AllNotEqualsIgnoreCase();

public static bool AllEqualsIgnoreCase(this IEnumerable<string> strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs.First()));
public static bool AllEqualsIgnoreCase(this IEnumerable<string?> strs) => strs is not null && !strs.Any(s => s.NotEqualsIgnoreCase(strs.First()));

public static bool AnyEqualsIgnoreCase(this IEnumerable<string> strs) => !strs.AllNotEqualsIgnoreCase();
public static bool AnyEqualsIgnoreCase(this IEnumerable<string?> strs) => !strs.AllNotEqualsIgnoreCase();

public static bool IsNotNull([NotNullWhen(true)] this string str) => str is not null;
public static bool IsNotNull([NotNullWhen(true)] this string? str) => str is not null;

public static bool AllNotNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsNull());
public static bool AllNotNull(params string?[] strs) => strs is not null && !strs.Any(s => s.IsNull());

public static bool AnyNotNull(params string[] strs) => strs is not null && strs.Any(s => s.IsNotNull());
public static bool AnyNotNull(params string?[] strs) => strs is not null && strs.Any(s => s.IsNotNull());

public static bool AllNotNull(this IEnumerable<string> strs) => strs is not null && !strs.Any(s => s.IsNull());
public static bool AllNotNull(this IEnumerable<string?> strs) => strs is not null && !strs.Any(s => s.IsNull());

public static bool AnyNotNull(this IEnumerable<string> strs) => strs is not null && strs.Any(s => s.IsNotNull());
public static bool AnyNotNull(this IEnumerable<string?> strs) => strs is not null && strs.Any(s => s.IsNotNull());

public static bool IsNotEmptyAndNull([NotNullWhen(true)] this string str) => !string.IsNullOrEmpty(str);
public static bool IsNotEmptyAndNull([NotNullWhen(true)] this string? str) => !string.IsNullOrEmpty(str);

public static bool AllNotEmptyAndNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsEmptyOrNull());
public static bool AllNotEmptyAndNull(params string?[] strs) => strs is not null && !strs.Any(s => s.IsEmptyOrNull());

public static bool AnyNotEmptyAndNull(params string[] strs) => strs is not null && strs.Any(s => s.IsNotEmptyAndNull());
public static bool AnyNotEmptyAndNull(params string?[] strs) => strs is not null && strs.Any(s => s.IsNotEmptyAndNull());

public static bool AllNotEmptyAndNull(this IEnumerable<string> strs) => strs is not null && !strs.Any(s => s.IsEmptyOrNull());
public static bool AllNotEmptyAndNull(this IEnumerable<string?> strs) => strs is not null && !strs.Any(s => s.IsEmptyOrNull());

public static bool AnyNotEmptyAndNull(this IEnumerable<string> strs) => strs is not null && strs.Any(s => s.IsNotEmptyAndNull());
public static bool AnyNotEmptyAndNull(this IEnumerable<string?> strs) => strs is not null && strs.Any(s => s.IsNotEmptyAndNull());

public static bool IsNotWhiteSpaceAndNull([NotNullWhen(true)] this string str) => !string.IsNullOrWhiteSpace(str);
public static bool IsNotWhiteSpaceAndNull([NotNullWhen(true)] this string? str) => !string.IsNullOrWhiteSpace(str);

public static bool AllNotWhiteSpaceAndNull(params string[] strs) => strs is not null && !strs.Any(s => s.IsWhiteSpaceOrNull());
public static bool AllNotWhiteSpaceAndNull(params string?[] strs) => strs is not null && !strs.Any(s => s.IsWhiteSpaceOrNull());

public static bool AnyNotWhiteSpaceAndNull(params string[] strs) => strs is not null && strs.Any(s => s.IsNotWhiteSpaceAndNull());
public static bool AnyNotWhiteSpaceAndNull(params string?[] strs) => strs is not null && strs.Any(s => s.IsNotWhiteSpaceAndNull());

public static bool AllNotWhiteSpaceAndNull(this IEnumerable<string> strs) => strs is not null && !strs.Any(s => s.IsWhiteSpaceOrNull());
public static bool AllNotWhiteSpaceAndNull(this IEnumerable<string?> strs) => strs is not null && !strs.Any(s => s.IsWhiteSpaceOrNull());

public static bool AnyNotWhiteSpaceAndNull(this IEnumerable<string> strs) => strs is not null && strs.Any(s => s.IsNotWhiteSpaceAndNull());
public static bool AnyNotWhiteSpaceAndNull(this IEnumerable<string?> strs) => strs is not null && strs.Any(s => s.IsNotWhiteSpaceAndNull());

public static bool NotEqualsIgnoreCase(this string str1, string str2) => AllNotNull(str1, str2) && !string.Equals(str1, str2, OrdinalIgnoreCase);
public static bool NotEqualsIgnoreCase(this string? str1, string? str2) => AllNotNull(str1, str2) && !string.Equals(str1, str2, OrdinalIgnoreCase);

public static bool AllNotEqualsIgnoreCase(params string[] strs)
public static bool AllNotEqualsIgnoreCase(params string?[] strs)
{
if (strs is null || strs.Length < 2)
{
return false;
}

var hashSet = new HashSet<string>(strs.Length, StringComparer.OrdinalIgnoreCase);
var hashSet = new HashSet<string?>(strs.Length, StringComparer.OrdinalIgnoreCase);

for (var i = 0; i < strs.Length; i++)
{
Expand All @@ -99,16 +99,16 @@ public static bool AllNotEqualsIgnoreCase(params string[] strs)
return true;
}

public static bool AnyNotEqualsIgnoreCase(params string[] strs) => !strs.AllEqualsIgnoreCase();
public static bool AnyNotEqualsIgnoreCase(params string?[] strs) => !strs.AllEqualsIgnoreCase();

public static bool AllNotEqualsIgnoreCase(this IEnumerable<string> strs)
public static bool AllNotEqualsIgnoreCase(this IEnumerable<string?> strs)
{
if (strs is null || strs.Count() < 2)
{
return false;
}

var hashSet = new HashSet<string>(strs.Count(), StringComparer.OrdinalIgnoreCase);
var hashSet = new HashSet<string?>(strs.Count(), StringComparer.OrdinalIgnoreCase);

foreach (var str in strs)
{
Expand All @@ -121,17 +121,17 @@ public static bool AllNotEqualsIgnoreCase(this IEnumerable<string> strs)
return true;
}

public static bool AnyNotEqualsIgnoreCase(this IEnumerable<string> strs) => !strs.AllEqualsIgnoreCase();
public static bool AnyNotEqualsIgnoreCase(this IEnumerable<string?> strs) => !strs.AllEqualsIgnoreCase();

public static string GetValue(this string str) => str ?? string.Empty;
public static string GetValue(this string? str) => str ?? string.Empty;

public static string GetValue(this string str, string dfltVal) => str ?? dfltVal;
public static string GetValue(this string? str, string dfltVal) => str ?? dfltVal;

public static string GetValue(this string str, char dfltVal) => str ?? (dfltVal.IsNotEmpty() ? dfltVal.ToString() : string.Empty);
public static string GetValue(this string? str, char dfltVal) => str ?? (dfltVal.IsNotEmpty() ? dfltVal.ToString() : string.Empty);

public static string ToLower(this string str) => str.IsNotWhiteSpaceAndNull() ? str.ToLower() : str;
public static string? ToLower(this string? str) => str.IsNotWhiteSpaceAndNull() ? str.ToLower() : str;

public static IEnumerable<string> ToLower(this IEnumerable<string> strs)
public static IEnumerable<string?> ToLower(this IEnumerable<string?> strs)
{
if (strs.IsEmptyOrNull())
{
Expand All @@ -144,9 +144,9 @@ public static IEnumerable<string> ToLower(this IEnumerable<string> strs)
}
}

public static string ToLowerInvariant(this string str) => str.IsNotWhiteSpaceAndNull() ? str.ToLower(CultureInfo.InvariantCulture) : str;
public static string? ToLowerInvariant(this string? str) => str.IsNotWhiteSpaceAndNull() ? str.ToLower(CultureInfo.InvariantCulture) : str;

public static IEnumerable<string> ToLowerInvariant(this IEnumerable<string> strs)
public static IEnumerable<string?> ToLowerInvariant(this IEnumerable<string?> strs)
{
if (strs.IsEmptyOrNull())
{
Expand All @@ -159,9 +159,9 @@ public static IEnumerable<string> ToLowerInvariant(this IEnumerable<string> strs
}
}

public static string ToUpper(this string str) => str.IsNotWhiteSpaceAndNull() ? str.ToUpper() : str;
public static string? ToUpper(this string? str) => str.IsNotWhiteSpaceAndNull() ? str.ToUpper() : str;

public static IEnumerable<string> ToUpper(this IEnumerable<string> strs)
public static IEnumerable<string?> ToUpper(this IEnumerable<string?> strs)
{
if (strs.IsEmptyOrNull())
{
Expand All @@ -174,9 +174,9 @@ public static IEnumerable<string> ToUpper(this IEnumerable<string> strs)
}
}

public static string ToUpperInvariant(this string str) => str.IsNotWhiteSpaceAndNull() ? str.ToUpper(CultureInfo.InvariantCulture) : str;
public static string? ToUpperInvariant(this string? str) => str.IsNotWhiteSpaceAndNull() ? str.ToUpper(CultureInfo.InvariantCulture) : str;

public static IEnumerable<string> ToUpperInvariant(this IEnumerable<string> strs)
public static IEnumerable<string?> ToUpperInvariant(this IEnumerable<string?> strs)
{
if (strs.IsEmptyOrNull())
{
Expand Down

0 comments on commit f6d8718

Please sign in to comment.