mirror of
https://github.com/aria2/aria2.git
synced 2026-04-02 10:55:00 +00:00
Added swap for UriStruct
This commit is contained in:
22
src/uri.cc
22
src/uri.cc
@@ -77,6 +77,28 @@ UriStruct& UriStruct::operator=(const UriStruct& c)
|
||||
return *this;
|
||||
}
|
||||
|
||||
void UriStruct::swap(UriStruct& other)
|
||||
{
|
||||
using std::swap;
|
||||
if(this != &other) {
|
||||
swap(protocol, other.protocol);
|
||||
swap(host, other.host);
|
||||
swap(port, other.port);
|
||||
swap(dir, other.dir);
|
||||
swap(file, other.file);
|
||||
swap(query, other.query);
|
||||
swap(username, other.username);
|
||||
swap(password, other.password);
|
||||
swap(hasPassword, other.hasPassword);
|
||||
swap(ipv6LiteralAddress, other.ipv6LiteralAddress);
|
||||
}
|
||||
}
|
||||
|
||||
void swap(UriStruct& lhs, UriStruct& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
bool parse(UriStruct& result, const std::string& uri)
|
||||
{
|
||||
// http://user:password@aria2.sourceforge.net:80/dir/file?query#fragment
|
||||
|
||||
@@ -60,8 +60,11 @@ struct UriStruct {
|
||||
~UriStruct();
|
||||
|
||||
UriStruct& operator=(const UriStruct& c);
|
||||
void swap(UriStruct& other);
|
||||
};
|
||||
|
||||
void swap(UriStruct& lhs, UriStruct& rhs);
|
||||
|
||||
// Splits URI uri into components and stores them into result. On
|
||||
// success returns true. Otherwise returns false and result is
|
||||
// undefined.
|
||||
|
||||
@@ -34,6 +34,7 @@ class UriTest:public CppUnit::TestFixture {
|
||||
CPPUNIT_TEST(testSetUri_ipv6);
|
||||
CPPUNIT_TEST(testInnerLink);
|
||||
CPPUNIT_TEST(testConstruct);
|
||||
CPPUNIT_TEST(testSwap);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@@ -62,6 +63,7 @@ public:
|
||||
void testSetUri_ipv6();
|
||||
void testInnerLink();
|
||||
void testConstruct();
|
||||
void testSwap();
|
||||
};
|
||||
|
||||
|
||||
@@ -470,6 +472,19 @@ void UriTest::testConstruct()
|
||||
}
|
||||
}
|
||||
|
||||
void UriTest::testSwap()
|
||||
{
|
||||
UriStruct us1;
|
||||
CPPUNIT_ASSERT(parse(us1, "http://u1:p1@[::1]/dir1/file1?k1=v1"));
|
||||
UriStruct us2;
|
||||
CPPUNIT_ASSERT(parse(us2, "ftp://host2/dir2/file2?k2=v2"));
|
||||
us1.swap(us2);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp://host2/dir2/file2?k2=v2"),
|
||||
construct(us1));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://u1:p1@[::1]/dir1/file1?k1=v1"),
|
||||
construct(us2));
|
||||
}
|
||||
|
||||
} // namespace uri
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
Reference in New Issue
Block a user