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

#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="ENotFound" />
public static int VerifyListIndexOf( int idx ) =>
   idx >= 0 ? idx : throw new ENotFound(
      "String was not found among list elements." );

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

[u.failure_as_minus_1]
public static int ListIndexOf( string str, List<string> strings ) =>
   ListIndexOf( str, strings, false );
[u.failure_as_minus_1]
public static int InvariantListIndexOf( string str, List<string> strings ) =>
   InvariantListIndexOf( str, strings, false );
[u.failure_as_minus_1]
public static int CCListIndexOf( string str, List<string> strings ) =>
   CCListIndexOf( str, strings, false );

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

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

public static bool IsOneOf( string str, List<string> strings ) =>
   IsOneOf( str, strings, false );
public static bool InvariantIsOneOf( string str, List<string> strings ) =>
   InvariantIsOneOf( str, strings, false );
public static bool CCIsOneOf( string str, List<string> strings ) =>
   CCIsOneOf( str, strings, false );

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

[u.failure_as_minus_1]
public static int ListIndexOf( string str, List<string> strings, bool ignoreCase )
{
   for ( int i=0; i<strings.Count; i++ )
      if ( Equals( str, strings[ i ], ignoreCase ) )
         return i;
   return -1;
}
[u.failure_as_minus_1]
public static int InvariantListIndexOf( string str, List<string> strings, bool ignoreCase )
{
   for ( int i=0; i<strings.Count; i++ )
      if ( CompareInvariant( str, strings[ i ], ignoreCase ) == 0 )
         return i;
   return -1;
}
[u.failure_as_minus_1]
public static int CCListIndexOf( string str, List<string> strings, bool ignoreCase )
{
   for ( int i=0; i<strings.Count; i++ )
      if ( CompareCC( str, strings[ i ], ignoreCase ) == 0 )
         return i;
   return -1;
}

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

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

public static bool IsOneOf( string str, List<string> strings, bool ignoreCase ) =>
   ListIndexOf( str, strings, ignoreCase ) >= 0;
public static bool InvariantIsOneOf( string str, List<string> strings, bool ignoreCase ) =>
   InvariantListIndexOf( str, strings, ignoreCase ) >= 0;
public static bool CCIsOneOf( string str, List<string> strings, bool ignoreCase ) =>
   CCListIndexOf( str, strings, ignoreCase ) >= 0;

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

} // user_rtx (.wasm)
