mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
clean-up
This commit is contained in:
parent
8267d2860b
commit
785b3f253d
1 changed files with 19 additions and 19 deletions
|
|
@ -137,8 +137,6 @@ static_assert((MAGIC_ENUM_RANGE_MAX - MAGIC_ENUM_RANGE_MIN) < (std::numeric_limi
|
||||||
// If need custom names for enum, add specialization enum_name for necessary enum type.
|
// If need custom names for enum, add specialization enum_name for necessary enum type.
|
||||||
template <typename E>
|
template <typename E>
|
||||||
constexpr string_view enum_name(E) noexcept {
|
constexpr string_view enum_name(E) noexcept {
|
||||||
static_assert(std::is_enum_v<E>, "magic_enum::customize::enum_name requires enum type.");
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,6 +144,9 @@ constexpr string_view enum_name(E) noexcept {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
template <typename... T>
|
||||||
|
inline constexpr bool always_false_v = false;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct supported
|
struct supported
|
||||||
#if defined(MAGIC_ENUM_SUPPORTED) && MAGIC_ENUM_SUPPORTED || defined(MAGIC_ENUM_NO_CHECK_SUPPORT)
|
#if defined(MAGIC_ENUM_SUPPORTED) && MAGIC_ENUM_SUPPORTED || defined(MAGIC_ENUM_NO_CHECK_SUPPORT)
|
||||||
|
|
@ -230,15 +231,22 @@ constexpr string_view pretty_name(string_view name) noexcept {
|
||||||
return {}; // Invalid name.
|
return {}; // Invalid name.
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename CharType>
|
class case_insensitive {
|
||||||
constexpr auto to_lower([[maybe_unused]] CharType ch) noexcept -> std::enable_if_t<std::is_same_v<std::decay_t<CharType>, char>, char> {
|
static constexpr char to_lower(char c) noexcept {
|
||||||
|
return (c >= 'A' && c <= 'Z') ? static_cast<char>(c + ('a' - 'A')) : c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
template <typename L, typename R>
|
||||||
|
constexpr auto operator()([[maybe_unused]] L lhs, [[maybe_unused]] R rhs) noexcept -> std::enable_if_t<std::is_same_v<std::decay_t<L>, char> && std::is_same_v<std::decay_t<R>, char>, bool> {
|
||||||
#if defined(MAGIC_ENUM_ENABLE_NONASCII)
|
#if defined(MAGIC_ENUM_ENABLE_NONASCII)
|
||||||
static_assert(!std::is_same_v<CharType, CharType>, "magic_enum::detail::to_lower not supported Non-ASCII feature.");
|
static_assert(always_false_v<L, R>, "magic_enum::case_insensitive not supported Non-ASCII feature.");
|
||||||
return {};
|
return false;
|
||||||
#else
|
#else
|
||||||
return 'A' <= ch && ch <= 'Z' ? ch - 'A' + 'a' : ch;
|
return to_lower(lhs) == to_lower(rhs);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
constexpr std::size_t find(string_view str, char c) noexcept {
|
constexpr std::size_t find(string_view str, char c) noexcept {
|
||||||
#if defined(__clang__) && __clang_major__ < 9 && defined(__GLIBCXX__) || defined(_MSC_VER) && _MSC_VER < 1920 && !defined(__clang__)
|
#if defined(__clang__) && __clang_major__ < 9 && defined(__GLIBCXX__) || defined(_MSC_VER) && _MSC_VER < 1920 && !defined(__clang__)
|
||||||
|
|
@ -808,15 +816,7 @@ template <typename E>
|
||||||
}
|
}
|
||||||
|
|
||||||
// allows you to write magic_enum::enum_cast<foo>("bar", magic_enum::case_insensitive);
|
// allows you to write magic_enum::enum_cast<foo>("bar", magic_enum::case_insensitive);
|
||||||
inline constexpr auto case_insensitive = [](auto lhs, auto rhs) noexcept
|
inline constexpr auto case_insensitive = detail::case_insensitive{};
|
||||||
-> std::enable_if_t<std::is_same_v<std::decay_t<decltype(lhs)>, char> && std::is_same_v<std::decay_t<decltype(rhs)>, char>, bool> {
|
|
||||||
#if defined(MAGIC_ENUM_ENABLE_NONASCII)
|
|
||||||
static_assert(!std::is_same_v<decltype(lhs), decltype(lhs)>, "magic_enum::case_insensitive not supported Non-ASCII feature.");
|
|
||||||
return {};
|
|
||||||
#else
|
|
||||||
return detail::to_lower(lhs) == detail::to_lower(rhs);
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
// Obtains enum value from name.
|
// Obtains enum value from name.
|
||||||
// Returns optional with enum value.
|
// Returns optional with enum value.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue