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

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

/// <summary>
/// Culture helpers
/// </summary>
public static class culture {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static CultureInfo CurrentUINeutralCulture =>
   ToNeutral( CultureInfo.CurrentUICulture );

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

public static NotSupportedException NotSupportedOperationException() =>
   NotSupportedOperationException( CultureInfo.CurrentCulture );

public static NotSupportedException NotSupportedOperationException( CultureInfo? culture ) =>
   new NotSupportedException(string.Format(
      "Operation is not supported for this culture: “{0}”.",
      culture ?? CultureInfo.InvariantCulture ));

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

public static CultureInfo ToNeutral( CultureInfo? culture )
{
   for ( var ci=culture;;ci=ci.Parent )
      if ( ci == null || ci == CultureInfo.InvariantCulture )
         return CultureInfo.InvariantCulture;
      else
         if ( ci.IsNeutralCulture )
            return ci==culture ? (CultureInfo)ci.Clone() : ci;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // culture

} // user_rtx (.wasm)
