Skip to content

Commit

Permalink
Merge pull request #25 from I-RzR-I/feature/25042024AddNewExtension
Browse files Browse the repository at this point in the history
Add new string extensions: `AsRedacted`, `TrimPrefix`, `TrimSuffix`.
  • Loading branch information
I-RzR-I authored May 18, 2024
2 parents 93cbbd4 + 1ad9a46 commit 1cd61e7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
5 changes: 4 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@
### **v1.1.1.7310**
-> Adjust and clean up code execution.<br />
-> Reorganize typeparam extensions.<br />
-> Add new typeparam extensions: `IfIsNull`, `IfIsNotNull`, `IfIsNullOrFuncIsTrue`, `IfIsNullAndFuncIsTrue`, `IfFuncIsTrue`, `IfFuncIsFalse`, `IfFunc`, `IfNull`, `IfNotNull`.<br />
-> Add new typeparam extensions: `IfIsNull`, `IfIsNotNull`, `IfIsNullOrFuncIsTrue`, `IfIsNullAndFuncIsTrue`, `IfFuncIsTrue`, `IfFuncIsFalse`, `IfFunc`, `IfNull`, `IfNotNull`.<br />

### **v1.1.2.3434**
-> Add new string extensions: `AsRedacted`, `TrimPrefix`, `TrimSuffix`.<br />
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ public static string AddHashFragment(this string url, string query)

return url + query;
}

/// <summary>
/// Get origin from URL
/// </summary>
Expand Down Expand Up @@ -1402,5 +1402,54 @@ public static string Obfuscate(this string source)

return "****" + last4Chars;
}

/// <summary>
/// Return string as redacted value
/// </summary>
/// <param name="source">Source string</param>
/// <returns></returns>
/// <remarks></remarks>
public static string AsRedacted(this string source)
=> "***REDACTED***";

/// <summary>
/// Return string prefix trimmed
/// </summary>
/// <param name="source">Source string</param>
/// <param name="prefix">Prefix to be checked</param>
/// <param name="stringComparision">String comparision type. Default OrdinalIgnoreCase.</param>
/// <returns></returns>
/// <remarks></remarks>
public static string TrimPrefix(this string source, string prefix, StringComparison stringComparision = StringComparison.OrdinalIgnoreCase)
{
if (source.IsMissing() || prefix.IsMissing()) return source;

if (source.StartsWith(prefix, stringComparision))
{
return source.Substring(prefix.Length);
}

return source;
}

/// <summary>
/// Return string suffix trimmed
/// </summary>
/// <param name="source">Source string</param>
/// <param name="suffix">Suffix to be checked</param>
/// <param name="stringComparision">String comparision type. Default OrdinalIgnoreCase.</param>
/// <returns></returns>
/// <remarks></remarks>
public static string TrimSuffix(this string source, string suffix, StringComparison stringComparision = StringComparison.OrdinalIgnoreCase)
{
if (source.IsMissing() || suffix.IsMissing()) return source;

if (source.EndsWith(suffix, stringComparision))
{
return source.Substring(0, source.Length - suffix.Length);
}

return source;
}
}
}
6 changes: 3 additions & 3 deletions src/shared/GeneralAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
#endif

[assembly: AssemblyVersion("1.1.1.7310")]
[assembly: AssemblyFileVersion("1.1.1.7310")]
[assembly: AssemblyInformationalVersion("1.1.1.7310")]
[assembly: AssemblyVersion("1.1.2.3434")]
[assembly: AssemblyFileVersion("1.1.2.3434")]
[assembly: AssemblyInformationalVersion("1.1.2.3434")]

0 comments on commit 1cd61e7

Please sign in to comment.