diff options
author | Vincent Richard <[email protected]> | 2014-01-19 16:25:25 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2014-01-19 16:25:25 +0000 |
commit | 58bad6e4887bd41c17f3b89a70a1837356a12ebf (patch) | |
tree | ec8238632d6f15b34473fedd235f75b2d0501267 /src | |
parent | Better error message. (diff) | |
download | vmime-58bad6e4887bd41c17f3b89a70a1837356a12ebf.tar.gz vmime-58bad6e4887bd41c17f3b89a70a1837356a12ebf.zip |
Path to/from string conversion.
Diffstat (limited to 'src')
-rw-r--r-- | src/vmime/utility/path.cpp | 47 | ||||
-rw-r--r-- | src/vmime/utility/path.hpp | 19 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/vmime/utility/path.cpp b/src/vmime/utility/path.cpp index 59685866..aaa3192e 100644 --- a/src/vmime/utility/path.cpp +++ b/src/vmime/utility/path.cpp @@ -261,5 +261,52 @@ path::component& path::getComponentAt(const size_t pos) } +// static +path path::fromString(const string& str, const string& sep, const charset& cset) +{ + path p; + + size_t start = 0; + size_t end = 0; + + do + { + end = str.find(sep, start); + + string comp; + + if (end == string::npos) + comp = str.substr(start); + else + comp = str.substr(start, end - start); + + // Skip leading or trailing separators + if (comp.length()) + p.appendComponent(component(comp, cset)); + + start = end + 1; + } + while (end != string::npos); + + return p; +} + + +const string path::toString(const string& sep, const charset& cset) +{ + string str; + + for (size_t i = 0 ; i < m_list.size() ; ++i) + { + if (i != 0) + str += sep; + + str += m_list[i].getConvertedText(cset); + } + + return str; +} + + } // utility } // vmime diff --git a/src/vmime/utility/path.hpp b/src/vmime/utility/path.hpp index 203da246..02fd9ce6 100644 --- a/src/vmime/utility/path.hpp +++ b/src/vmime/utility/path.hpp @@ -158,6 +158,25 @@ public: */ void renameParent(const path& oldPath, const path& newPath); + /** Construct a new path from a string. + * + * @param str string representation of the path + * @param sep separator string (eg: "/") + * @param cset charset in which the path is encoded (use the value returned by + * vmime::charset::getLocalCharset() to use the default charset of your system) + * @return a new path corresponding to the specified string + */ + static path fromString(const string& str, const string& sep, const charset& cset); + + /** Returns a string representation of this path. + * + * @param sep separator string (eg: "/") + * @param cset charset in which to encode the components (use the value returned by + * vmime::charset::getLocalCharset() to use the default charset of your system) + * @return a string representing this path + */ + const string toString(const string& sep, const charset& cset); + private: list m_list; |