T_FSPathStyle - Most methods made constexpr

This commit is contained in:
Emmanuel BENOîT 2018-12-22 09:17:16 +01:00
parent af1648dcb4
commit 96d81b9cd3
3 changed files with 54 additions and 42 deletions

View file

@ -36,34 +36,41 @@ class T_FSPathStyle
// - whether it is case-sensitive,
// - whether is can use a drive letter as its root,
// - which separators it supports
T_FSPathStyle( bool cs , bool hdl , T_Flags< E_FSPathSeparator > ps ) noexcept;
constexpr T_FSPathStyle( bool cs , bool hdl ,
T_Flags< E_FSPathSeparator > ps ) noexcept;
// Default copy/move constructors/assignement operators
T_FSPathStyle( T_FSPathStyle const& ) noexcept = default;
T_FSPathStyle& operator =( T_FSPathStyle const& ) noexcept = default;
T_FSPathStyle( T_FSPathStyle&& ) noexcept = default;
T_FSPathStyle& operator =( T_FSPathStyle&& ) noexcept = default;
constexpr T_FSPathStyle( T_FSPathStyle const& ) noexcept = default;
constexpr T_FSPathStyle& operator =( T_FSPathStyle const& ) noexcept = default;
constexpr T_FSPathStyle( T_FSPathStyle&& ) noexcept = default;
constexpr T_FSPathStyle& operator =( T_FSPathStyle&& ) noexcept = default;
T_FSPathStyle& swap( T_FSPathStyle& other ) noexcept;
//----------------------------------------------------------------------
// Accessors
bool caseSensitive( ) const noexcept;
T_FSPathStyle& caseSensitive( bool cs ) noexcept;
constexpr bool caseSensitive( ) const noexcept;
constexpr T_FSPathStyle& caseSensitive( bool cs ) noexcept;
bool hasDriveLetter( ) const noexcept;
T_FSPathStyle& hasDriveLetter( bool hdl ) noexcept;
constexpr bool hasDriveLetter( ) const noexcept;
constexpr T_FSPathStyle& hasDriveLetter( bool hdl ) noexcept;
T_Flags< E_FSPathSeparator > pathSeparators( ) const noexcept;
T_FSPathStyle& pathSeparator( T_Flags< E_FSPathSeparator > ps ) noexcept;
constexpr T_Flags< E_FSPathSeparator > pathSeparators( ) const noexcept;
constexpr T_FSPathStyle& pathSeparator( T_Flags< E_FSPathSeparator > ps ) noexcept;
//----------------------------------------------------------------------
// Checks
constexpr bool isSeparator( T_Character chr ) const noexcept;
bool isValidRoot( T_String const& string ) const noexcept;
//----------------------------------------------------------------------
// Pre-initialised styles
static T_FSPathStyle Unix( );
static T_FSPathStyle Windows( );
static T_FSPathStyle System( );
static constexpr T_FSPathStyle Unix( );
static constexpr T_FSPathStyle Windows( );
static constexpr T_FSPathStyle System( );
};

View file

@ -11,7 +11,7 @@ namespace ebcl {
/*= T_FSPathStyle ============================================================*/
inline T_FSPathStyle::T_FSPathStyle(
inline constexpr T_FSPathStyle::T_FSPathStyle(
bool cs ,
bool hdl ,
T_Flags< E_FSPathSeparator > ps ) noexcept
@ -34,34 +34,34 @@ inline T_FSPathStyle& T_FSPathStyle::swap(
/*----------------------------------------------------------------------------*/
inline bool T_FSPathStyle::caseSensitive( ) const noexcept
inline constexpr bool T_FSPathStyle::caseSensitive( ) const noexcept
{
return caseSensitive_;
}
inline T_FSPathStyle& T_FSPathStyle::caseSensitive( bool cs ) noexcept
inline constexpr T_FSPathStyle& T_FSPathStyle::caseSensitive( bool cs ) noexcept
{
caseSensitive_ = cs;
return *this;
}
inline bool T_FSPathStyle::hasDriveLetter( ) const noexcept
inline constexpr bool T_FSPathStyle::hasDriveLetter( ) const noexcept
{
return hasDriveLetter_;
}
inline T_FSPathStyle& T_FSPathStyle::hasDriveLetter( bool hdl ) noexcept
inline constexpr T_FSPathStyle& T_FSPathStyle::hasDriveLetter( bool hdl ) noexcept
{
hasDriveLetter_ = hdl;
return *this;
}
inline T_Flags< E_FSPathSeparator > T_FSPathStyle::pathSeparators( ) const noexcept
inline constexpr T_Flags< E_FSPathSeparator > T_FSPathStyle::pathSeparators( ) const noexcept
{
return pathSeparators_;
}
inline T_FSPathStyle& T_FSPathStyle::pathSeparator(
inline constexpr T_FSPathStyle& T_FSPathStyle::pathSeparator(
T_Flags< E_FSPathSeparator > ps ) noexcept
{
assert( ps );
@ -71,19 +71,28 @@ inline T_FSPathStyle& T_FSPathStyle::pathSeparator(
/*----------------------------------------------------------------------------*/
inline T_FSPathStyle T_FSPathStyle::Unix( )
inline constexpr bool T_FSPathStyle::isSeparator(
const T_Character chr ) const noexcept
{
return ( ( pathSeparators_ & E_FSPathSeparator::SLASH ) && chr == '/' )
|| ( ( pathSeparators_ & E_FSPathSeparator::SLASH ) && chr == '\\' );
}
/*----------------------------------------------------------------------------*/
inline constexpr T_FSPathStyle T_FSPathStyle::Unix( )
{
return T_FSPathStyle{ true , false ,
T_Flags< E_FSPathSeparator >{ E_FSPathSeparator::SLASH } };
}
inline T_FSPathStyle T_FSPathStyle::Windows( )
inline constexpr T_FSPathStyle T_FSPathStyle::Windows( )
{
return T_FSPathStyle{ false , true ,
T_Flags< E_FSPathSeparator >{ E_FSPathSeparator::BACKSLASH } };
}
inline T_FSPathStyle T_FSPathStyle::System( )
inline constexpr T_FSPathStyle T_FSPathStyle::System( )
{
#ifdef _WIN32
return T_FSPathStyle::Windows( );

View file

@ -14,28 +14,24 @@ using namespace ebcl;
#endif
/*= T_FSPath =================================================================*/
/*= T_FSPathStyle ============================================================*/
bool T_FSPath::IsValidRoot(
T_String const& str ) noexcept
bool T_FSPathStyle::isValidRoot(
T_String const& string ) const noexcept
{
if ( !str ) {
return true;
}
#ifdef _WIN32
// TODO: support for network names (\\server\path)
if ( str.length( ) == 3 && ( str.endsWith( ":\\" )
|| str.endsWith( ":/" ) ) ) {
return str[ 0 ].isAlpha( );
} else {
return ( str == "/" || str == "\\" );
}
#else
return ( str == "/" || str == "\\" );
#endif
const auto sl( string.length( ) );
return ( sl == 0 )
|| ( sl == 1 && isSeparator( string[ 0 ] ) )
|| ( hasDriveLetter_
&& string.length( ) == 3
&& string[ 0 ].isAlpha( )
&& string[ 1 ] == ':'
&& isSeparator( string[ 2 ] ) );
}
/*= T_FSPath =================================================================*/
bool T_FSPath::IsValidComponent(
T_String const& str ) noexcept
{