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

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

/// <summary>
/// Stack trace helpers
/// </summary>
public class stack_trace {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[MethodImpl( MethodImplOptions.NoInlining )]
public static string GetText() =>
   ToText( new StackTrace( 1 ) );

[MethodImpl( MethodImplOptions.NoInlining )]
public static string GetText( bool needFileInfo ) =>
   ToText( new StackTrace( needFileInfo ) );

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

[MethodImpl( MethodImplOptions.NoInlining )]
public static string GetText( int skipFrames ) =>
   ToText( new StackTrace( skipFrames + 1 ) );

[MethodImpl( MethodImplOptions.NoInlining )]
public static string GetText( int skipFrames, bool needFileInfo ) =>
   ToText( new StackTrace( skipFrames + 1, needFileInfo ) );

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

public static string ToText( StackTrace stackTrace )
{
   string str = stackTrace.ToString();
   int len = str.Length, l = len;
   l -= str.EndsWith( "\r\n" ) ? 2 :
      str.EndsWith( '\n' ) || str.EndsWith( '\r' ) ? 1 : 0;
   return ( l<len ? str.Remove( l ) : str ).TXT();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // stack_trace

} // user_rtx (.wasm)
