string Pathname::basename( const Pathname & name_tv )
{
if ( name_tv.empty() )
- return "";
+ return string();
string ret_t( name_tv.asString() );
ret_t.erase( 0, name_tv.prfx_i );
return ret_t;
}
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : Pathname::extension
+ // METHOD TYPE : string
+ //
+ string Pathname::extension( const Pathname & name_tv )
+ {
+ if ( name_tv.empty() )
+ return string();
+
+ string base( basename( name_tv ) );
+ string::size_type pos = base.rfind( '.' );
+ if ( pos == string::npos )
+ return string();
+ return base.substr( pos );
+ }
+
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : Pathname::cat
std::string basename() const { return basename( *this ); }
static std::string basename( const Pathname & name_tv );
+ /** Return all of the characters in name after and including
+ * the last dot in the last element of name. If there is no dot
+ * in the last element of name then returns the empty string.
+ */
+ std::string extension() const { return extension( *this ); }
+ static std::string extension( const Pathname & name_tv );
+
/** Return this path, adding a leading '/' if relative. */
Pathname absolutename() const { return absolutename( *this ); }
static Pathname absolutename( const Pathname & name_tv )