1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:57:35 +00:00

LibRegex: Allow RegexOptions to be declared at compile time

This commit is contained in:
Timothy Flynn 2021-07-29 09:30:58 -04:00 committed by Linus Groh
parent f1809db994
commit 4a72b2c879

View file

@ -74,13 +74,13 @@ public:
RegexOptions() = default; RegexOptions() = default;
RegexOptions(T flags) constexpr RegexOptions(T flags)
: m_flags(flags) : m_flags(flags)
{ {
} }
template<class U> template<class U>
RegexOptions(RegexOptions<U> other) constexpr RegexOptions(RegexOptions<U> other)
: m_flags((T) static_cast<FlagsUnderlyingType>(other.value())) : m_flags((T) static_cast<FlagsUnderlyingType>(other.value()))
{ {
} }
@ -88,16 +88,16 @@ public:
operator bool() const { return !!*this; } operator bool() const { return !!*this; }
bool operator!() const { return (FlagsUnderlyingType)m_flags == 0; } bool operator!() const { return (FlagsUnderlyingType)m_flags == 0; }
RegexOptions<T> operator|(T flag) const { return RegexOptions<T> { (T)((FlagsUnderlyingType)m_flags | (FlagsUnderlyingType)flag) }; } constexpr RegexOptions<T> operator|(T flag) const { return RegexOptions<T> { (T)((FlagsUnderlyingType)m_flags | (FlagsUnderlyingType)flag) }; }
RegexOptions<T> operator&(T flag) const { return RegexOptions<T> { (T)((FlagsUnderlyingType)m_flags & (FlagsUnderlyingType)flag) }; } constexpr RegexOptions<T> operator&(T flag) const { return RegexOptions<T> { (T)((FlagsUnderlyingType)m_flags & (FlagsUnderlyingType)flag) }; }
RegexOptions<T>& operator|=(T flag) constexpr RegexOptions<T>& operator|=(T flag)
{ {
m_flags = (T)((FlagsUnderlyingType)m_flags | (FlagsUnderlyingType)flag); m_flags = (T)((FlagsUnderlyingType)m_flags | (FlagsUnderlyingType)flag);
return *this; return *this;
} }
RegexOptions<T>& operator&=(T flag) constexpr RegexOptions<T>& operator&=(T flag)
{ {
m_flags = (T)((FlagsUnderlyingType)m_flags & (FlagsUnderlyingType)flag); m_flags = (T)((FlagsUnderlyingType)m_flags & (FlagsUnderlyingType)flag);
return *this; return *this;
@ -114,19 +114,19 @@ private:
}; };
template<class T> template<class T>
inline RegexOptions<T> operator|(T lhs, T rhs) constexpr RegexOptions<T> operator|(T lhs, T rhs)
{ {
return RegexOptions<T> { lhs } |= rhs; return RegexOptions<T> { lhs } |= rhs;
} }
template<class T> template<class T>
inline RegexOptions<T> operator&(T lhs, T rhs) constexpr RegexOptions<T> operator&(T lhs, T rhs)
{ {
return RegexOptions<T> { lhs } &= rhs; return RegexOptions<T> { lhs } &= rhs;
} }
template<class T> template<class T>
inline T operator~(T flag) constexpr T operator~(T flag)
{ {
return (T) ~((FlagsUnderlyingType)flag); return (T) ~((FlagsUnderlyingType)flag);
} }