Strings - T_Character is now mostly constexpr
This commit is contained in:
parent
ee02f9c5c7
commit
af1648dcb4
2 changed files with 56 additions and 54 deletions
|
@ -69,39 +69,39 @@ struct T_Character
|
|||
|
||||
const uint32_t codepoint;
|
||||
|
||||
T_Character( ) noexcept;
|
||||
T_Character( T_Character const& other ) noexcept;
|
||||
M_WITH_INT( T ) T_Character( T codepoint ) noexcept;
|
||||
constexpr T_Character( ) noexcept;
|
||||
constexpr T_Character( T_Character const& other ) noexcept;
|
||||
M_WITH_INT( T ) constexpr T_Character( T codepoint ) noexcept;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
bool isValid( ) const;
|
||||
bool isAscii( ) const;
|
||||
bool isControl( ) const;
|
||||
bool isUppercase( ) const;
|
||||
bool isLowercase( ) const;
|
||||
bool isAlpha( ) const;
|
||||
bool isNumeric( ) const;
|
||||
bool isAlphanumeric( ) const;
|
||||
bool isWhitespace( ) const;
|
||||
constexpr bool isValid( ) const;
|
||||
constexpr bool isAscii( ) const;
|
||||
constexpr bool isControl( ) const;
|
||||
constexpr bool isUppercase( ) const;
|
||||
constexpr bool isLowercase( ) const;
|
||||
constexpr bool isAlpha( ) const;
|
||||
constexpr bool isNumeric( ) const;
|
||||
constexpr bool isAlphanumeric( ) const;
|
||||
constexpr bool isWhitespace( ) const;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
bool operator== ( T_Character const& other ) const;
|
||||
bool operator!= ( T_Character const& other ) const;
|
||||
bool operator< ( T_Character const& other ) const;
|
||||
bool operator> ( T_Character const& other ) const;
|
||||
bool operator<= ( T_Character const& other ) const;
|
||||
bool operator>= ( T_Character const& other ) const;
|
||||
constexpr bool operator== ( T_Character const& other ) const;
|
||||
constexpr bool operator!= ( T_Character const& other ) const;
|
||||
constexpr bool operator< ( T_Character const& other ) const;
|
||||
constexpr bool operator> ( T_Character const& other ) const;
|
||||
constexpr bool operator<= ( T_Character const& other ) const;
|
||||
constexpr bool operator>= ( T_Character const& other ) const;
|
||||
|
||||
M_WITH_INT( T ) bool operator== ( T other ) const;
|
||||
M_WITH_INT( T ) bool operator!= ( T other ) const;
|
||||
M_WITH_INT( T ) bool operator< ( T other ) const;
|
||||
M_WITH_INT( T ) bool operator<= ( T other ) const;
|
||||
M_WITH_INT( T ) bool operator> ( T other ) const;
|
||||
M_WITH_INT( T ) bool operator>= ( T other ) const;
|
||||
M_WITH_INT( T ) constexpr bool operator== ( T other ) const;
|
||||
M_WITH_INT( T ) constexpr bool operator!= ( T other ) const;
|
||||
M_WITH_INT( T ) constexpr bool operator< ( T other ) const;
|
||||
M_WITH_INT( T ) constexpr bool operator<= ( T other ) const;
|
||||
M_WITH_INT( T ) constexpr bool operator> ( T other ) const;
|
||||
M_WITH_INT( T ) constexpr bool operator>= ( T other ) const;
|
||||
|
||||
operator uint32_t ( ) const;
|
||||
constexpr operator uint32_t ( ) const;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
@ -109,8 +109,8 @@ struct T_Character
|
|||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
T_Character toUpper( ) const;
|
||||
T_Character toLower( ) const;
|
||||
constexpr T_Character toUpper( ) const;
|
||||
constexpr T_Character toLower( ) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -10,16 +10,18 @@ namespace ebcl {
|
|||
|
||||
/*= T_Character ==============================================================*/
|
||||
|
||||
inline T_Character::T_Character( ) noexcept
|
||||
inline constexpr T_Character::T_Character( ) noexcept
|
||||
: codepoint( 0 )
|
||||
{ }
|
||||
|
||||
inline T_Character::T_Character( const T_Character& other ) noexcept
|
||||
inline constexpr T_Character::T_Character(
|
||||
const T_Character& other ) noexcept
|
||||
: codepoint( other.codepoint )
|
||||
{ }
|
||||
|
||||
template< typename T , typename >
|
||||
inline T_Character::T_Character( T codepoint ) noexcept
|
||||
inline constexpr T_Character::T_Character(
|
||||
T codepoint ) noexcept
|
||||
: codepoint( uint32_t( codepoint ) )
|
||||
{
|
||||
assert( codepoint >= 0 );
|
||||
|
@ -27,47 +29,47 @@ inline T_Character::T_Character( T codepoint ) noexcept
|
|||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
inline bool T_Character::isValid( ) const
|
||||
inline constexpr bool T_Character::isValid( ) const
|
||||
{
|
||||
return codepoint < 0x110000;
|
||||
}
|
||||
|
||||
inline bool T_Character::isAscii( ) const
|
||||
inline constexpr bool T_Character::isAscii( ) const
|
||||
{
|
||||
return codepoint < 128;
|
||||
}
|
||||
|
||||
inline bool T_Character::isControl( ) const
|
||||
inline constexpr bool T_Character::isControl( ) const
|
||||
{
|
||||
return codepoint < 32;
|
||||
}
|
||||
|
||||
inline bool T_Character::isUppercase( ) const
|
||||
inline constexpr bool T_Character::isUppercase( ) const
|
||||
{
|
||||
return codepoint >= 'A' && codepoint <= 'Z';
|
||||
}
|
||||
|
||||
inline bool T_Character::isLowercase( ) const
|
||||
inline constexpr bool T_Character::isLowercase( ) const
|
||||
{
|
||||
return codepoint >= 'a' && codepoint <= 'z';
|
||||
}
|
||||
|
||||
inline bool T_Character::isAlpha( ) const
|
||||
inline constexpr bool T_Character::isAlpha( ) const
|
||||
{
|
||||
return isUppercase( ) || isLowercase( );
|
||||
}
|
||||
|
||||
inline bool T_Character::isNumeric( ) const
|
||||
inline constexpr bool T_Character::isNumeric( ) const
|
||||
{
|
||||
return codepoint >= '0' && codepoint <= '9';
|
||||
}
|
||||
|
||||
inline bool T_Character::isAlphanumeric( ) const
|
||||
inline constexpr bool T_Character::isAlphanumeric( ) const
|
||||
{
|
||||
return isAlpha( ) || isNumeric( );
|
||||
}
|
||||
|
||||
inline bool T_Character::isWhitespace( ) const
|
||||
inline constexpr bool T_Character::isWhitespace( ) const
|
||||
{
|
||||
return codepoint == 32 || codepoint == '\t'
|
||||
|| codepoint == '\n' || codepoint == '\r';
|
||||
|
@ -75,32 +77,32 @@ inline bool T_Character::isWhitespace( ) const
|
|||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
inline bool T_Character::operator== ( T_Character const& other ) const
|
||||
inline constexpr bool T_Character::operator== ( T_Character const& other ) const
|
||||
{
|
||||
return codepoint == other.codepoint;
|
||||
}
|
||||
|
||||
inline bool T_Character::operator!= ( T_Character const& other ) const
|
||||
inline constexpr bool T_Character::operator!= ( T_Character const& other ) const
|
||||
{
|
||||
return codepoint != other.codepoint;
|
||||
}
|
||||
|
||||
inline bool T_Character::operator< ( T_Character const& other ) const
|
||||
inline constexpr bool T_Character::operator< ( T_Character const& other ) const
|
||||
{
|
||||
return codepoint < other.codepoint;
|
||||
}
|
||||
|
||||
inline bool T_Character::operator> ( T_Character const& other ) const
|
||||
inline constexpr bool T_Character::operator> ( T_Character const& other ) const
|
||||
{
|
||||
return codepoint > other.codepoint;
|
||||
}
|
||||
|
||||
inline bool T_Character::operator<= ( T_Character const& other ) const
|
||||
inline constexpr bool T_Character::operator<= ( T_Character const& other ) const
|
||||
{
|
||||
return codepoint <= other.codepoint;
|
||||
}
|
||||
|
||||
inline bool T_Character::operator>= ( T_Character const& other ) const
|
||||
inline constexpr bool T_Character::operator>= ( T_Character const& other ) const
|
||||
{
|
||||
return codepoint >= other.codepoint;
|
||||
}
|
||||
|
@ -108,44 +110,44 @@ inline bool T_Character::operator>= ( T_Character const& other ) const
|
|||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename T , typename >
|
||||
inline bool T_Character::operator== ( T other ) const
|
||||
inline constexpr bool T_Character::operator== ( T other ) const
|
||||
{
|
||||
return codepoint == uint32_t( other );
|
||||
}
|
||||
|
||||
template< typename T , typename >
|
||||
inline bool T_Character::operator!= ( T other ) const
|
||||
inline constexpr bool T_Character::operator!= ( T other ) const
|
||||
{
|
||||
return codepoint != uint32_t( other );
|
||||
}
|
||||
|
||||
template< typename T , typename >
|
||||
inline bool T_Character::operator< ( T other ) const
|
||||
inline constexpr bool T_Character::operator< ( T other ) const
|
||||
{
|
||||
return codepoint < uint32_t( other );
|
||||
}
|
||||
|
||||
template< typename T , typename >
|
||||
inline bool T_Character::operator<= ( T other ) const
|
||||
inline constexpr bool T_Character::operator<= ( T other ) const
|
||||
{
|
||||
return codepoint <= uint32_t( other );
|
||||
}
|
||||
|
||||
template< typename T , typename >
|
||||
inline bool T_Character::operator> ( T other ) const
|
||||
inline constexpr bool T_Character::operator> ( T other ) const
|
||||
{
|
||||
return codepoint > uint32_t( other );
|
||||
}
|
||||
|
||||
template< typename T , typename >
|
||||
inline bool T_Character::operator>= ( T other ) const
|
||||
inline constexpr bool T_Character::operator>= ( T other ) const
|
||||
{
|
||||
return codepoint >= uint32_t( other );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
inline T_Character::operator uint32_t ( ) const
|
||||
inline constexpr T_Character::operator uint32_t ( ) const
|
||||
{
|
||||
return codepoint;
|
||||
}
|
||||
|
@ -159,7 +161,7 @@ inline uint32_t T_Character::writeTo( char* output , uint32_t avail ) const
|
|||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
inline T_Character T_Character::toUpper( ) const
|
||||
inline constexpr T_Character T_Character::toUpper( ) const
|
||||
{
|
||||
if ( isLowercase( ) ) {
|
||||
return *this & (~0x20);
|
||||
|
@ -168,7 +170,7 @@ inline T_Character T_Character::toUpper( ) const
|
|||
}
|
||||
}
|
||||
|
||||
inline T_Character T_Character::toLower( ) const
|
||||
inline constexpr T_Character T_Character::toLower( ) const
|
||||
{
|
||||
if ( isUppercase( ) ) {
|
||||
return *this | 0x20;
|
||||
|
|
Loading…
Reference in a new issue