From d0ffbb60e654d39b6e22dc2be1693d9d676c997f Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 16 Jan 2014 00:15:21 +0100 Subject: Use equivalence instead of strict equality for path components. --- src/vmime/utility/path.cpp | 9 ++++----- src/vmime/word.cpp | 6 ++++++ src/vmime/word.hpp | 8 ++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/vmime/utility/path.cpp b/src/vmime/utility/path.cpp index 9f746d54..59685866 100644 --- a/src/vmime/utility/path.cpp +++ b/src/vmime/utility/path.cpp @@ -134,8 +134,7 @@ bool path::operator==(const path& p) const bool equal = true; for ( ; equal && i != m_list.end() ; ++i, ++j) - //equal = (*i == *j); - equal = ((*i).getBuffer() == (*j).getBuffer()); + equal = ((*i).isEquivalent(*j)); return (equal); } @@ -197,7 +196,7 @@ bool path::isDirectParentOf(const path& p) const bool equal = true; for (list::size_type i = 0 ; equal && i < m_list.size() ; ++i) - equal = (m_list[i] == p.m_list[i]); + equal = (m_list[i].isEquivalent(p.m_list[i])); return (equal); } @@ -211,7 +210,7 @@ bool path::isParentOf(const path& p) const bool equal = true; for (list::size_type i = 0 ; equal && i < m_list.size() ; ++i) - equal = (m_list[i] == p.m_list[i]); + equal = (m_list[i].isEquivalent(p.m_list[i])); return (equal); } @@ -226,7 +225,7 @@ void path::renameParent(const path& oldPath, const path& newPath) list::size_type i; for (i = 0 ; equal && i < oldPath.m_list.size() ; ++i) - equal = (m_list[i] == oldPath.m_list[i]); + equal = (m_list[i].isEquivalent(oldPath.m_list[i])); if (i != oldPath.m_list.size()) return; diff --git a/src/vmime/word.cpp b/src/vmime/word.cpp index 2ee4d3e7..4b99fbc3 100644 --- a/src/vmime/word.cpp +++ b/src/vmime/word.cpp @@ -723,6 +723,12 @@ bool word::operator!=(const word& w) const } +bool word::isEquivalent(const word& other) const +{ + return getConvertedText(charset(charsets::UTF_8)) == other.getConvertedText(charset(charsets::UTF_8)); +} + + const string word::getConvertedText(const charset& dest, const charsetConverterOptions& opts) const { string out; diff --git a/src/vmime/word.hpp b/src/vmime/word.hpp index a6e2402e..4122228d 100644 --- a/src/vmime/word.hpp +++ b/src/vmime/word.hpp @@ -85,6 +85,14 @@ public: */ void setCharset(const charset& ch); + /** Returns whether two words actually represent the same text, + * regardless of their charset. + * + * @param other word to compare to + * @return true if the two words represent the same text, or false otherwise + */ + bool isEquivalent(const word& other) const; + word& operator=(const word& w); word& operator=(const string& s); -- cgit v1.2.3