From 7521be3c5fca53e8318585114ec24c73aa949fd7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 23 Apr 2021 18:03:24 +0200 Subject: [PATCH] [libcalamares] Add find() to namedenumtable that takes a default value --- src/libcalamares/utils/NamedEnum.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcalamares/utils/NamedEnum.h b/src/libcalamares/utils/NamedEnum.h index 1d839ddc4..1462cc0ff 100644 --- a/src/libcalamares/utils/NamedEnum.h +++ b/src/libcalamares/utils/NamedEnum.h @@ -174,6 +174,22 @@ struct NamedEnumTable 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. * * If @p s is an enum value in the table, return the corresponding