Strings - T_Character is now mostly constexpr

This commit is contained in:
Emmanuel BENOîT 2018-12-20 22:30:44 +01:00
parent ee02f9c5c7
commit af1648dcb4
2 changed files with 56 additions and 54 deletions
include/ebcl/inline

View file

@ -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;