//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Text;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

static partial class str {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <summary>
/// Text normalization (CR,LF)
/// </summary>
public static string TXT( string multilineStr ) =>
   AppendText( new StringBuilder(), multilineStr ).ToString();

/// <summary>
/// Text normalization (CR,LF) for nullable string
/// </summary>
public static string? TXT_N( string? multilineStr ) =>
   multilineStr!=null ? TXT( multilineStr ) : null;
/// <summary>
/// Text normalization (CR,LF), or empty result (for null argument)
/// </summary>
public static string TXT_E( string? multilineStr ) =>
   multilineStr!=null ? TXT( multilineStr ) : "";

//--------------------------------------------------------------------------------------------------

[u.returns_source]
public static StringBuilder AppendText( StringBuilder sb, string multilineStr ) =>
   AppendText( sb, true, multilineStr );
[u.returns_source]
public static StringBuilder AppendText( StringBuilder sb,
                                        [u.def_true] bool insertLineIfNotEmpty,
                                        string multilineStr )
{
   if ( insertLineIfNotEmpty )
      u.text.AppendLine( sb );
   foreach ( char ch in multilineStr )
      if ( ch == '\n' )
         sb.AppendLine();
      else
         if ( ch != '\r' )
            sb.Append( ch );
   return sb;
}

//==================================================================================================

/// <summary>
/// Text format with normalization (CR,LF)
/// </summary>
public static string FMT( string messageFmt, params object?[] args ) =>
   TXT( string.Format( messageFmt, args ) );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // str

} // user_rtx (.wasm)
