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

#if !WASM
namespace CommonHelpers {
#else
namespace CommonHelpers.WASM {
#endif

//**************************************************************************************************
partial class HNumParser {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static T Parse<T>(string src,NumberStyles styles) where T: struct
   { return Parse<T>(src,styles,NumberFormatInfo.CurrentInfo); }
public static T Parse<T>(string src,NumberStyles styles,T def) where T: struct
   { return Parse<T>(src,styles,NumberFormatInfo.CurrentInfo,def); }

public static T Parse<T>(string src,NumberStyles styles,IFormatProvider provider)
   where T: struct
{
   return HValueParser.Parse<T>(src,new object[]{styles,provider});
}
public static T Parse<T>(string src,NumberStyles styles,IFormatProvider provider,T def)
   where T: struct
{
   return HValueParser.Parse<T>(src,new object[]{styles,provider},def);
}

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

public static T ParseInvariant<T>(string src) where T: struct
   { return HValueParser.Parse<T>(src,NumberFormatInfo.InvariantInfo); }
public static T ParseInvariant<T>(string src, T def) where T: struct
   { return HValueParser.Parse<T>(src,NumberFormatInfo.InvariantInfo,def); }

public static T ParseInvariant<T>(string src,NumberStyles styles) where T: struct
   { return Parse<T>(src,styles,NumberFormatInfo.InvariantInfo); }
public static T ParseInvariant<T>(string src,NumberStyles styles,T def) where T: struct
   { return Parse<T>(src,styles,NumberFormatInfo.InvariantInfo,def); }

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

public static T ParseEx<T>( string src, NumberStyles styles,
                            [HOptional] IFormatProvider provider,
                            T? def ) where T: struct
{
   return HValueParser.ParseWithParamsEx<T>( src,
      provider!=null ? new object[]{ styles, provider } : new object[]{ styles },
      def );
}

public static T ParseInvariant<T>(string src,NumberStyles styles,T? def) where T: struct
{
   return HValueParser.ParseWithParamsEx<T>( src,
      new object[]{ styles, (IFormatProvider)null },
      def );
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HNumParser
//**************************************************************************************************

} // CommonHelpers (.WASM)
