Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Benchmarks/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class StringExtensionBenchmark
/// Benchmark for the RemoveCharacters method.
/// </summary>
[Benchmark]
public string RemoveCharacters()
public string? RemoveCharacters()
{
return input.RemoveCharacters(charactersToRemove);
}
Expand Down Expand Up @@ -64,7 +64,7 @@ public int CountSubstring()
/// Benchmark for the ReverseWords method.
/// </summary>
[Benchmark]
public string ReverseWords()
public string? ReverseWords()
{
return input.ReverseWords();
}
Expand All @@ -91,7 +91,7 @@ public int CountLetters()
/// Benchmark for the RemoveDuplicateCharacters method.
/// </summary>
[Benchmark]
public string RemoveDuplicateCharacters()
public string? RemoveDuplicateCharacters()
{
return input.RemoveDuplicateCharacters();
}
Expand Down
17 changes: 11 additions & 6 deletions StringExtension/Casing/Casing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static class Casing
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The input string converted to camel case.</returns>
public static string ToCamelCase(this string input)
/// <remarks>Returns <see cref="string.Empty"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string ToCamelCase(this string? input)
{
return ToCamelCase(input.AsSpan());
}
Expand Down Expand Up @@ -96,7 +97,8 @@ public static string ToCamelCase(this ReadOnlySpan<char> input)
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The input string converted to Pascal case.</returns>
public static string ToPascalCase(this string input)
/// <remarks>Returns <see cref="string.Empty"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string ToPascalCase(this string? input)
{
return ToPascalCase(input.AsSpan());
}
Expand Down Expand Up @@ -156,7 +158,8 @@ public static string ToPascalCase(this ReadOnlySpan<char> input)
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The input string converted to snake case.</returns>
public static string ToSnakeCase(this string input)
/// <remarks>Returns <see cref="string.Empty"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string ToSnakeCase(this string? input)
{
return ToSnakeCase(input.AsSpan());
}
Expand All @@ -183,7 +186,8 @@ public static string ToSnakeCase(this ReadOnlySpan<char> input)
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The input string converted to kebab case.</returns>
public static string ToKebabCase(this string input)
/// <remarks>Returns <see cref="string.Empty"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string ToKebabCase(this string? input)
{
return ToKebabCase(input.AsSpan());
}
Expand Down Expand Up @@ -215,7 +219,8 @@ public static string ToKebabCase(this ReadOnlySpan<char> input)
/// If <see langword="false"/> (the default), every word is capitalized.
/// </param>
/// <returns>The input string converted to title case.</returns>
public static string ToTitleCase(this string input, bool useEnglishMinorWordRules = false)
/// <remarks>Returns <see cref="string.Empty"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string ToTitleCase(this string? input, bool useEnglishMinorWordRules = false)
{
return ToTitleCase(input.AsSpan(), useEnglishMinorWordRules);
}
Expand Down Expand Up @@ -405,7 +410,7 @@ private static bool IsEnglishMinorWord(ReadOnlySpan<char> word)
/// stripped or transliterated. Returns <see cref="string.Empty"/> if
/// <paramref name="input"/> is <see langword="null"/> or empty.
/// </remarks>
public static string Slugify(this string input, char separator = '-')
public static string Slugify(this string? input, char separator = '-')
{
if (string.IsNullOrEmpty(input))
{
Expand Down
6 changes: 4 additions & 2 deletions StringExtension/Linguistics/Linguistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static class Linguistics
/// </summary>
/// <param name="input">The input string.</param>
/// <returns><c>true</c> if the string is a palindrome; otherwise, <c>false</c>.</returns>
public static bool IsPalindrome(this string input)
/// <remarks>Returns <see langword="false"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static bool IsPalindrome(this string? input)
{
return IsPalindrome(input.AsSpan());
}
Expand Down Expand Up @@ -83,7 +84,8 @@ public static bool IsPalindrome(this ReadOnlySpan<char> input)
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The number of letters in the input string.</returns>
public static int CountLetters(this string input)
/// <remarks>Returns <c>0</c> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static int CountLetters(this string? input)
{
return CountLetters(input.AsSpan());
}
Expand Down
9 changes: 5 additions & 4 deletions StringExtension/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class StringExtension
/// <param name="charactersToRemove">An array of characters to remove.</param>
/// <returns>A new string with specified characters removed.</returns>
/// <remarks>Returns <see langword="null"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string RemoveCharacters(this string input, char[] charactersToRemove)
public static string? RemoveCharacters(this string? input, char[]? charactersToRemove)
{
if (string.IsNullOrEmpty(input) || charactersToRemove is null || charactersToRemove.Length == 0)
{
Expand Down Expand Up @@ -71,7 +71,8 @@ public static string RemoveCharacters(this ReadOnlySpan<char> input, ReadOnlySpa
/// <param name="input">The input string.</param>
/// <param name="substring">The substring to count.</param>
/// <returns>The number of occurrences of the substring in the input string.</returns>
public static int CountSubstring(this string input, string substring)
/// <remarks>Returns <c>0</c> if <paramref name="input"/> or <paramref name="substring"/> is <see langword="null"/>.</remarks>
public static int CountSubstring(this string? input, string? substring)
{
return CountSubstring(input.AsSpan(), substring.AsSpan());
}
Expand Down Expand Up @@ -99,7 +100,7 @@ public static int CountSubstring(this ReadOnlySpan<char> input, ReadOnlySpan<cha
/// <param name="input">The input to reverse words.</param>
/// <returns>The input string with the order of words reversed.</returns>
/// <remarks>Returns <see langword="null"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string ReverseWords(this string input)
public static string? ReverseWords(this string? input)
{
if (string.IsNullOrEmpty(input))
{
Expand Down Expand Up @@ -133,7 +134,7 @@ public static string ReverseWords(this string input)
/// <param name="input">The input string.</param>
/// <returns>A new string with duplicate characters removed.</returns>
/// <remarks>Returns <see langword="null"/> if <paramref name="input"/> is <see langword="null"/>.</remarks>
public static string RemoveDuplicateCharacters(this string input)
public static string? RemoveDuplicateCharacters(this string? input)
{
if (string.IsNullOrEmpty(input))
{
Expand Down
6 changes: 4 additions & 2 deletions StringExtension/Validation/Validation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static partial class Validation
/// </summary>
/// <param name="email">The email address to validate.</param>
/// <returns><c>true</c> if the given email address is valid; otherwise, <c>false</c>.</returns>
public static bool IsValidEmail(this string email)
/// <remarks>Returns <see langword="false"/> if <paramref name="email"/> is <see langword="null"/>.</remarks>
public static bool IsValidEmail(this string? email)
{
return !string.IsNullOrEmpty(email) && MailAddressRegex().IsMatch(email);
}
Expand All @@ -46,7 +47,8 @@ public static bool IsValidEmail(this ReadOnlySpan<char> email)
/// </summary>
/// <param name="phoneNumber">The phone number to validate.</param>
/// <returns><c>true</c> if the given phone number is valid; otherwise, <c>false</c>.</returns>
public static bool IsValidPhoneNumber(this string phoneNumber)
/// <remarks>Returns <see langword="false"/> if <paramref name="phoneNumber"/> is <see langword="null"/>.</remarks>
public static bool IsValidPhoneNumber(this string? phoneNumber)
{
return !string.IsNullOrEmpty(phoneNumber) && PhoneNumberRegex().IsMatch(phoneNumber);
}
Expand Down
11 changes: 5 additions & 6 deletions UnitTests/StringExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void TestRemoveCharacters()
string input = "hello world!";
char[] charactersToRemove = { 'l', 'o' };
string expected = "he wrd!";
string result = input.RemoveCharacters(charactersToRemove);
string? result = input.RemoveCharacters(charactersToRemove);
Assert.That(result, Is.EqualTo(expected));
}

Expand All @@ -31,7 +31,7 @@ public void TestRemoveCharacters_NullInput()
{
string input = null!;
char[] charactersToRemove = { 'l', 'o' };
string result = input.RemoveCharacters(charactersToRemove);
string? result = input.RemoveCharacters(charactersToRemove);
Assert.That(result, Is.Null);
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public void TestReverseWords()
{
string input = "hello world!";
string expected = "world! hello";
string result = input.ReverseWords();
string? result = input.ReverseWords();
Assert.That(result, Is.EqualTo(expected));
}

Expand All @@ -102,7 +102,7 @@ public void TestReverseWords()
public void TestReverseWords_NullInput()
{
string input = null!;
string result = input.ReverseWords();
string? result = input.ReverseWords();
Assert.That(result, Is.Null);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public void TestRemoveDuplicateCharacters()
{
string input = "hello world!";
string expected = "helo wrd!";
string result = input.RemoveDuplicateCharacters();
string? result = input.RemoveDuplicateCharacters();
Assert.That(result, Is.EqualTo(expected));
}

Expand Down Expand Up @@ -330,7 +330,6 @@ public void TestToTitleCase_LastWordAlwaysCapitalized()
Assert.That(result, Is.EqualTo(expected));
}


/// <summary>
/// Tests the Slugify method with accented characters and punctuation.
/// </summary>
Expand Down
Loading