Skip to content
Open
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: 6 additions & 0 deletions src/Bolt.Common.Extensions.UnitTests/StringExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,11 @@ public void IsEndWithTest()
var sut = "Hello world";
sut.IsEndWith("WORLD").ShouldBeTrue();
}

[Theory]
[InlineData("", " cups", "")]
[InlineData("12", " cups", "12 cups")]
public void AppendIfNotEmpty(string source, string ending, string result) =>
source.AppendIfNotEmpty(ending).ShouldBe(result);
}
}
10 changes: 10 additions & 0 deletions src/Bolt.Common.Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,15 @@ public static string FormatWith(this string source, params object[] args)
{
return string.Format(source, args);
}

/// <summary>
/// Appends an ending to a string if the source string is not empty
/// </summary>
/// <param name="source"></param>
/// <param name="ending"></param>
/// <returns></returns>
[DebuggerStepThrough]
public static string AppendIfNotEmpty(this string source, string ending) =>
source.IsEmpty() ? source : string.Concat(source, ending);
}
}