From 0f707ed4408bf4b96e22f96d78e9e371725e0b38 Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Tue, 28 May 2024 13:31:26 +0200 Subject: [PATCH 1/2] Add SeStringBuilder.AppendNewLine --- src/Lumina/Text/SeStringBuilder.Presets.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Lumina/Text/SeStringBuilder.Presets.cs b/src/Lumina/Text/SeStringBuilder.Presets.cs index d46bc8f7..cc2ddcd4 100644 --- a/src/Lumina/Text/SeStringBuilder.Presets.cs +++ b/src/Lumina/Text/SeStringBuilder.Presets.cs @@ -44,6 +44,11 @@ public SeStringBuilder AppendStringExpression( ReadOnlySeStringSpan rosss ) => public SeStringBuilder AppendStringExpression( ReadOnlySpan< char > str ) => BeginStringExpression().Append( str ).EndExpression(); + /// Appends a line break. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendNewLine() => + BeginMacro( MacroCode.NewLine ).EndMacro(); + /// Appends an icon. /// The icon ID. /// A reference of this instance after the append operation is completed. From 0dc2c6268b6521a1ced95699fd586909deeae594 Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Tue, 28 May 2024 13:31:54 +0200 Subject: [PATCH 2/2] Add SeStringBuilder.AppendLine --- src/Lumina/Text/SeStringBuilder.AppendLine.cs | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/Lumina/Text/SeStringBuilder.AppendLine.cs diff --git a/src/Lumina/Text/SeStringBuilder.AppendLine.cs b/src/Lumina/Text/SeStringBuilder.AppendLine.cs new file mode 100644 index 00000000..236ccc5a --- /dev/null +++ b/src/Lumina/Text/SeStringBuilder.AppendLine.cs @@ -0,0 +1,150 @@ +using Lumina.Text.ReadOnly; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Text; + +namespace Lumina.Text; + +/// A builder for . +public sealed partial class SeStringBuilder +{ + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlySpan< char > value ) => Append( value ).AppendNewLine(); + + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( Span< char > value ) => AppendLine( (ReadOnlySpan< char >) value ); + + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlyMemory< char > value ) => AppendLine( value.Span ); + + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( Memory< char > value ) => AppendLine( value.Span ); + + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( char[] value ) => AppendLine( value.AsSpan() ); + + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// The starting position of the substring within . + /// The number of characters in to append. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( char[] value, int startIndex, int count ) + => AppendLine( value.AsSpan( startIndex, count ) ); + + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( string? value ) => AppendLine( value.AsSpan() ); + + /// Adds the given UTF-16 char sequence and a line break. + /// Text to add. + /// The starting position of the substring within . + /// The number of characters in to append. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( string? value, int startIndex, int count ) + => AppendLine( value.AsSpan( startIndex, count ) ); + + /// Adds the given UTF-8 byte sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlySpan< byte > value ) => Append( value ).AppendNewLine(); + + /// Adds the given UTF-8 byte sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( Span< byte > value ) => AppendLine( (ReadOnlySpan< byte >) value ); + + /// Adds the given UTF-8 byte sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlyMemory< byte > value ) => AppendLine( value.Span ); + + /// Adds the given UTF-8 byte sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( Memory< byte > value ) => AppendLine( value.Span ); + + /// Adds the given UTF-8 byte sequence and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( byte[] value ) => AppendLine( value.AsSpan() ); + + /// Adds the given UTF-8 byte sequence and a line break. + /// Text to add. + /// The starting position of the substring within . + /// The number of characters in to append. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( byte[] value, int startIndex, int count ) + => AppendLine( value.AsSpan( startIndex, count ) ); + + /// Adds the given SeString from the given StringBuilder and a line break. + /// The string builder that contains the substring to append. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( StringBuilder value ) => Append( value ).AppendNewLine(); + + /// Adds the given SeString from the given StringBuilder and a line break. + /// The string builder that contains the substring to append. + /// The starting position of the substring within . + /// The number of characters in to append. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( StringBuilder value, int startIndex, int count ) + => Append( value, startIndex, count ).AppendNewLine(); + + /// Adds the given SeString and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( SeString value ) => Append( value ).AppendNewLine(); + + /// Adds the given SeString and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlySeString value ) => Append( value ).AppendNewLine(); + + /// Adds the given SeString payload, wrapping in envelope as needed, and a line break. + /// Payload to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlySePayload value ) => Append( value ).AppendNewLine(); + + /// Adds the given SeString expression, which is an invalid operation. + /// Expression to add. + [Obsolete( "You cannot append a SeExpression to a SeString.", true )] + [SuppressMessage( "ReSharper", "UnusedParameter.Global", Justification = "Trap for invalid append call from implicit casts with overloads." )] + public void AppendLine( ReadOnlySeExpression value ) => throw new InvalidOperationException(); + + /// Adds the given SeString and a line break. + /// Text to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlySeStringSpan value ) => Append( value ).AppendNewLine(); + + /// Adds the given SeString payload, wrapping in envelope as needed, and a line break. + /// Payload to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( ReadOnlySePayloadSpan value ) => Append( value ).AppendNewLine(); + + /// Adds the given SeString expression, which is an invalid operation. + /// Expression to add. + [Obsolete( "You cannot append a SeExpression to a SeString.", true )] + [SuppressMessage( "ReSharper", "UnusedParameter.Global", Justification = "Trap for invalid append call from implicit casts with overloads." )] + public void AppendLine( ReadOnlySeExpressionSpan value ) => throw new InvalidOperationException(); + + /// Adds the given value and a line break. + /// Value to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine( object? value ) => Append( value ).AppendNewLine(); + + /// Adds the given value and a line break. + /// Value to add. + /// A reference of this instance after the append operation is completed. + public SeStringBuilder AppendLine< T >( scoped in T value ) where T : struct + => Append( value ).AppendNewLine(); +} \ No newline at end of file