using System.Runtime.CompilerServices;
using System.Text;
namespace SharedTools.Text;
///
/// Appends lines with LF, the same line break on every system.
///
///
/// StringBuilder.AppendLine writes Environment.NewLine, which is CR LF on Windows: a text built with it differs between
/// the systems, and it mixes two kinds of line breaks as soon as one of its parts comes with LF. These members carry a
/// name of their own, because C# always prefers the instance method AppendLine over an extension of the same name.
///
public static class StringBuilderExtensions
{
private const char LINE_FEED = '\n';
/// The builder to append to.
extension(StringBuilder builder)
{
///
/// Appends a line break, LF.
///
/// The builder, to append more.
public StringBuilder AppendLineLF() => builder.Append(LINE_FEED);
///
/// Appends a text and a line break, LF.
///
/// The text; for null, only the line break.
/// The builder, to append more.
public StringBuilder AppendLineLF(string? value) => builder.Append(value).Append(LINE_FEED);
///
/// Appends an interpolated text and a line break, LF.
///
///
/// Like StringBuilder.AppendLine, the handler writes the text right into the builder, without a string in
/// between; afterward, only the line break is missing.
///
/// The handler which the compiler creates for the interpolated text.
/// The builder, to append more.
public StringBuilder AppendLineLF([InterpolatedStringHandlerArgument("builder")] ref StringBuilder.AppendInterpolatedStringHandler handler) => builder.Append(LINE_FEED);
}
}