[libcalamares] Add find() to namedenumtable that takes a default value

This commit is contained in:
Adriaan de Groot 2021-04-23 18:03:24 +02:00
parent 61557cf805
commit 7521be3c5f

View File

@ -174,6 +174,22 @@ struct NamedEnumTable
return table.begin()->second; return table.begin()->second;
} }
/** @brief Find a name @p s in the table.
*
* Searches case-insensitively.
*
* If the name @p s is not found, the value @p d is returned as
* a default. Otherwise the value corresponding to @p s is returned.
* This is a shortcut over find() using a bool to distinguish
* successful and unsuccesful lookups.
*/
enum_t find( const string_t& s, enum_t d ) const
{
bool ok = false;
enum_t e = find( s, ok );
return ok ? e : d;
}
/** @brief Find a value @p s in the table and return its name. /** @brief Find a value @p s in the table and return its name.
* *
* If @p s is an enum value in the table, return the corresponding * If @p s is an enum value in the table, return the corresponding