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

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

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

/// <exception cref="ArgumentException" />
public static int VerifyArgListIndexOf( int idx ) =>
   idx >= 0 ? idx : throw new ArgumentException(
      "String was not found among the arguments." );

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

/// <exception cref="ArgumentException" />
[u.failure_as_minus_1]
public static int ListIndexOf( string str, params string[] strings ) =>
   ListIndexOf( false, str, strings );
/// <exception cref="ArgumentException" />
[u.failure_as_minus_1]
public static int InvariantListIndexOf( string str, params string[] strings ) =>
   InvariantListIndexOf( false, str, strings );
/// <exception cref="ArgumentException" />
[u.failure_as_minus_1]
public static int CCListIndexOf( string str, params string[] strings ) =>
   CCListIndexOf( false, str, strings );

/// <exception cref="ArgumentException" />
[u.strict_result]
public static int StrictListIndexOf( string str, params string[] strings ) =>
   StrictListIndexOf( false, str, strings );
/// <exception cref="ArgumentException" />
[u.strict_result]
public static int StrictInvariantListIndexOf( string str, params string[] strings ) =>
   StrictInvariantListIndexOf( false, str, strings );
/// <exception cref="ArgumentException" />
[u.strict_result]
public static int StrictCCListIndexOf( string str, params string[] strings ) =>
   StrictCCListIndexOf( false, str, strings );

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

/// <exception cref="ArgumentException" />
public static bool IsOneOf( string str, params string[] strings ) =>
   IsOneOf( false, str, strings );
/// <exception cref="ArgumentException" />
public static bool InvariantIsOneOf( string str, params string[] strings ) =>
   InvariantIsOneOf( false, str, strings );
/// <exception cref="ArgumentException" />
public static bool CCIsOneOf( string str, params string[] strings ) =>
   CCIsOneOf( false, str, strings );

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

/// <exception cref="ArgumentException" />
[u.failure_as_minus_1]
public static int ListIndexOf( bool ignoreCase, string str, params string[] strings )
{
   u.array_argcheck.ZeroBased( strings, nameof(strings) );
   for ( int i=0; i<strings.Length; i++ )
      if ( Equals( str, strings[ i ], ignoreCase ) )
         return i;
   return -1;
}
/// <exception cref="ArgumentException" />
[u.failure_as_minus_1]
public static int InvariantListIndexOf( bool ignoreCase, string str, params string[] strings )
{
   u.array_argcheck.ZeroBased( strings, nameof(strings) );
   for ( int i=0; i<strings.Length; i++ )
      if ( CompareInvariant( str, strings[ i ], ignoreCase ) == 0 )
         return i;
   return -1;
}
/// <exception cref="ArgumentException" />
[u.failure_as_minus_1]
public static int CCListIndexOf( bool ignoreCase, string str, params string[] strings )
{
   u.array_argcheck.ZeroBased( strings, nameof(strings) );
   for ( int i=0; i<strings.Length; i++ )
      if ( CompareCC( str, strings[ i ], ignoreCase ) == 0 )
         return i;
   return -1;
}

/// <exception cref="ArgumentException" />
[u.strict_result]
public static int StrictListIndexOf( bool ignoreCase, string str, params string[] strings ) =>
   VerifyArgListIndexOf( ListIndexOf( ignoreCase, str, strings ) );
/// <exception cref="ArgumentException" />
[u.strict_result]
public static int StrictInvariantListIndexOf( bool ignoreCase,
                                              string str, params string[] strings ) =>
   VerifyArgListIndexOf( InvariantListIndexOf( ignoreCase, str, strings ) );
/// <exception cref="ArgumentException" />
[u.strict_result]
public static int StrictCCListIndexOf( bool ignoreCase, string str, params string[] strings ) =>
   VerifyArgListIndexOf( CCListIndexOf( ignoreCase, str, strings ) );

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

/// <exception cref="ArgumentException" />
public static bool IsOneOf( bool ignoreCase, string str, params string[] strings ) =>
   ListIndexOf( ignoreCase, str, strings ) >= 0;
/// <exception cref="ArgumentException" />
public static bool InvariantIsOneOf( bool ignoreCase, string str, params string[] strings ) =>
   InvariantListIndexOf( ignoreCase, str, strings ) >= 0;
/// <exception cref="ArgumentException" />
public static bool CCIsOneOf( bool ignoreCase, string str, params string[] strings ) =>
   CCListIndexOf( ignoreCase, str, strings ) >= 0;

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

} // user_rtx (.wasm)
