Added RemoveLeaf() leaf method. Very handy for recursive directory
iteration code using a single KPath object. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21606 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -35,6 +35,8 @@ class KPath {
|
|||||||
|
|
||||||
const char *Leaf() const;
|
const char *Leaf() const;
|
||||||
status_t ReplaceLeaf(const char *newLeaf);
|
status_t ReplaceLeaf(const char *newLeaf);
|
||||||
|
bool RemoveLeaf();
|
||||||
|
// returns false, if nothing could be removed anymore
|
||||||
|
|
||||||
status_t Append(const char *toAppend, bool isComponent = true);
|
status_t Append(const char *toAppend, bool isComponent = true);
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,24 @@ KPath::ReplaceLeaf(const char *newLeaf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
KPath::RemoveLeaf()
|
||||||
|
{
|
||||||
|
// get the leaf -- bail out, if not initialized or only the "/" is left
|
||||||
|
const char *leaf = Leaf();
|
||||||
|
if (!leaf || leaf == fBuffer)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// chop off the leaf
|
||||||
|
int32 leafIndex = leaf - fBuffer;
|
||||||
|
fBuffer[leafIndex] = '\0';
|
||||||
|
fPathLength = leafIndex;
|
||||||
|
_ChopTrailingSlashes();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
KPath::Append(const char *component, bool isComponent)
|
KPath::Append(const char *component, bool isComponent)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user