diff options
author | Vincent Richard <[email protected]> | 2004-12-22 09:52:32 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2004-12-22 09:52:32 +0000 |
commit | 206b2dafcdd560663b30deac06e10081f397e2c0 (patch) | |
tree | 8ceb7dcf5a888dbab27b79704d630b959fc852fd | |
parent | Added isParentOf() function. (diff) | |
download | vmime-206b2dafcdd560663b30deac06e10081f397e2c0.tar.gz vmime-206b2dafcdd560663b30deac06e10081f397e2c0.zip |
Added renameParent() function.
-rw-r--r-- | src/utility/path.cpp | 27 | ||||
-rw-r--r-- | src/utility/path.hpp | 7 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/utility/path.cpp b/src/utility/path.cpp index 282af12e..24e3c56e 100644 --- a/src/utility/path.cpp +++ b/src/utility/path.cpp @@ -206,6 +206,33 @@ const bool path::isParentOf(const path& p) const } +void path::renameParent(const path& oldPath, const path& newPath) +{ + if (isEmpty() || oldPath.getSize() > getSize()) + return; + + bool equal = true; + list::size_type i; + + for (i = 0 ; equal && i < oldPath.m_list.size() ; ++i) + equal = (m_list[i] == oldPath.m_list[i]); + + if (i != oldPath.m_list.size()) + return; + + list newList; + + for (list::size_type j = 0 ; j < newPath.m_list.size() ; ++j) + newList.push_back(newPath.m_list[j]); + + for (list::size_type j = i ; j < m_list.size() ; ++j) + newList.push_back(m_list[j]); + + m_list.resize(newList.size()); + std::copy(newList.begin(), newList.end(), m_list.begin()); +} + + void path::appendComponent(const path::component& c) { m_list.push_back(c); diff --git a/src/utility/path.hpp b/src/utility/path.hpp index 933794f1..5f377f7a 100644 --- a/src/utility/path.hpp +++ b/src/utility/path.hpp @@ -139,6 +139,13 @@ public: */ const bool isParentOf(const path& p) const; + /** Rename a parent component in the path. + * + * @param oldPath old parent path + * @param newPath new parent path + */ + void renameParent(const path& oldPath, const path& newPath); + private: list m_list; |