31 m_dot(std::string::npos)
47 set( std::string(path) ) ;
56 G::Path::Path(
const Path & path ,
const std::string & tail_1 ,
const std::string & tail_2 )
59 pathAppend( tail_1 ) ;
60 pathAppend( tail_2 ) ;
68 void G::Path::set(
const std::string & path )
79 m_dot = std::string::npos ;
82 void G::Path::normalise()
84 char ns[2] ;
char s[2] ;
char ss[3] ;
87 ns[1] = s[1] = ss[2] =
'\0' ;
112 m_str.size() == 3U &&
113 m_str.at(1) ==
':' ) ) )
115 m_str.resize( m_str.size()-1U ) ;
119 if( has_leading_double_slash )
124 m_dot = m_str.rfind(
'.' ) ;
125 if( m_dot != std::string::npos && slash != std::string::npos && m_dot < slash )
126 m_dot = std::string::npos ;
129 if( m_dot != std::string::npos )
131 m_extension = (m_dot+1U) == m_str.length() ? std::string() : m_str.substr(m_dot+1U) ;
142 return dirnameImp().empty() ;
147 return !isAbsolute() ;
152 if( hasNetworkDrive() )
155 std::string str(m_str) ;
156 if( hasDriveLetter() )
157 str.erase( 0U , driveString().length() ) ;
167 std::string head( dirnameImp() ) ;
168 if( head.length() == 0 )
174 std::string result( m_str ) ;
175 result.erase( 0U , head.length() ) ;
177 result.erase( 0U , 1U ) ;
184 return Path( dirnameImp() ) ;
187 std::string G::Path::dirnameImp()
const
194 result = m_str.size() > 2 ? driveString() : std::string() ;
200 if( m_str.size() == 3U )
206 result = withoutTail() ;
207 if( result.length() == 2 )
208 result.append( slashString() ) ;
213 result = withoutTail() ;
219 size_t slash_count = 0U ;
220 for( std::string::const_iterator p = m_str.begin() ; p != m_str.end() ; ++p )
224 result = slash_count > 3U ? withoutTail() : std::string() ;
226 else if( hasNoSlash() || m_str.size() == 1U )
232 result = withoutTail() ;
233 if( result.length() == 0U )
234 result = slashString() ;
239 std::string G::Path::withoutTail()
const
245 bool G::Path::hasNoSlash()
const
253 G_ASSERT( position != std::string::npos ) ;
257 std::string G::Path::slashString()
262 std::string G::Path::doubleSlashString()
271 m_str.size() >= 2U &&
272 m_str.at(1U) ==
':' ;
275 bool G::Path::hasNetworkDrive()
const
284 std::string G::Path::driveString()
const
288 return std::string( 1U , m_str.at(0U) ) + std::string(
":") ;
293 if( m_dot != std::string::npos )
295 m_str.resize( m_dot ) ;
296 m_dot = std::string::npos ;
306 if( m_str.size() == 0U || m_str == slashString() ||
307 ( hasDriveLetter() && m_str == driveString() ) )
313 m_str.append( slashString() ) ;
315 m_str.append( tail ) ;
331 else if( p2 ==
Path() )
339 for( Strings::iterator p = list.begin() ; p != list.end() ; ++p )
349 for(
unsigned int part = 0U ;; part++ )
351 std::string front = path.dirnameImp() ;
352 std::string back = path.
basename() ;
355 if( back == std::string(
".") && no_dot && front.length() != 0U )
358 list.push_front( back ) ;
360 if( front.length() == 0U )
371 ( m_str.empty() && other.m_str.empty() ) ||
372 ( m_str == other.m_str ) ;
377 return m_str != other.m_str ;
std::string str() const
Returns the path string.
Path & operator=(const Path &other)
Assignment operator.
Path()
Default constructor.
std::string basename() const
Returns the path, excluding drive/directory parts.
Strings split(bool no_dot=true) const
Spits the path into a list of component parts.
std::list< std::string > Strings
A std::list of std::strings.
bool operator!=(const Path &path) const
Comparison operator.
std::string::size_type size_type
A std::size_t type.
bool hasDriveLetter() const
Returns true if the path has a leading drive letter (and the operating system uses drive letters)...
std::string extension() const
Returns the path's filename extension.
static bool usesDriveLetters()
bool simple() const
Returns true if the path is just a file/directory name without any separators.
bool isRelative() const
Returns true if the path is a relative path.
static unsigned int replaceAll(std::string &s, const std::string &from, const std::string &to)
Does a global replace on string 's', replacing all occurences of sub-string 'from' with 'to'...
static bool allowsSpaces()
bool isAbsolute() const
Returns !isRelative().
bool operator==(const Path &path) const
Comparison operator.
Path dirname() const
Returns the drive/directory parts of the path.
void pathAppend(const std::string &tail)
Appends a filename to the path.
static void removeAll(std::string &, char)
Removes all occurrences of the character from the string.
static bool leadingDoubleSlash()
A Path object represents a file system path.
void removeExtension()
Modifies the path by removing any extension.
static G::Path join(const G::Path &p1, const G::Path &p2)
Joins two paths together.