Use equivalence instead of strict equality for path components.

This commit is contained in:
Vincent Richard 2014-01-16 00:15:21 +01:00
parent fe43da096f
commit d0ffbb60e6
4 changed files with 33 additions and 6 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -26,7 +26,7 @@
#include "vmime/utility/path.hpp"
VMIME_TEST_SUITE_BEGIN(pathTest)
VMIME_TEST_SUITE_BEGIN(utilityPathTest)
VMIME_TEST_LIST_BEGIN
VMIME_TEST(testConstruct1)
@ -50,6 +50,7 @@ VMIME_TEST_SUITE_BEGIN(pathTest)
VMIME_TEST(testIsDirectParentOf)
VMIME_TEST(testIsParentOf)
VMIME_TEST(testIsParentOf_EquivalentCharset)
VMIME_TEST(testRenameParent)
VMIME_TEST_LIST_END
@ -271,6 +272,19 @@ VMIME_TEST_SUITE_BEGIN(pathTest)
VASSERT_EQ("4", false, p2.isParentOf(p1));
}
void testIsParentOf_EquivalentCharset()
{
path p1;
p1.appendComponent(comp("foo", "us-ascii"));
path p2;
p2.appendComponent(comp("foo", "utf-8"));
p2.appendComponent(comp("bar"));
p2.appendComponent(comp("baz"));
VASSERT_EQ("1", true, p1.isParentOf(p2));
}
void testRenameParent()
{
path p1;