mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 23:07:56 +02:00
Poco::URI: added new constructor to create URI from Path
This commit is contained in:
@@ -27,6 +27,9 @@
|
|||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
|
class Path;
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API URI
|
class Foundation_API URI
|
||||||
/// A Uniform Resource Identifier, as specified in RFC 3986.
|
/// A Uniform Resource Identifier, as specified in RFC 3986.
|
||||||
///
|
///
|
||||||
@@ -72,6 +75,12 @@ public:
|
|||||||
/// Creates an URI from a base URI and a relative URI, according to
|
/// Creates an URI from a base URI and a relative URI, according to
|
||||||
/// the algorithm in section 5.2 of RFC 3986.
|
/// the algorithm in section 5.2 of RFC 3986.
|
||||||
|
|
||||||
|
explicit URI(const Path& path);
|
||||||
|
/// Creates a URI from a path.
|
||||||
|
///
|
||||||
|
/// The path will be made absolute, and a file:// URI
|
||||||
|
/// will be built from it.
|
||||||
|
|
||||||
~URI();
|
~URI();
|
||||||
/// Destroys the URI.
|
/// Destroys the URI.
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/String.h"
|
#include "Poco/String.h"
|
||||||
#include "Poco/NumberParser.h"
|
#include "Poco/NumberParser.h"
|
||||||
|
#include "Poco/Path.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@@ -125,6 +126,16 @@ URI::URI(const URI& baseURI, const std::string& relativeURI):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
URI::URI(const Path& path):
|
||||||
|
_scheme("file"),
|
||||||
|
_port(0)
|
||||||
|
{
|
||||||
|
Path absolutePath(path);
|
||||||
|
absolutePath.makeAbsolute();
|
||||||
|
_path = absolutePath.toString(Path::PATH_UNIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
URI::~URI()
|
URI::~URI()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -14,9 +14,11 @@
|
|||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/URI.h"
|
#include "Poco/URI.h"
|
||||||
|
#include "Poco/Path.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::URI;
|
using Poco::URI;
|
||||||
|
using Poco::Path;
|
||||||
|
|
||||||
|
|
||||||
URITest::URITest(const std::string& name): CppUnit::TestCase(name)
|
URITest::URITest(const std::string& name): CppUnit::TestCase(name)
|
||||||
@@ -774,6 +776,22 @@ void URITest::testEncodeDecode()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void URITest::testFromPath()
|
||||||
|
{
|
||||||
|
Path path1("/var/www/site/index.html", Path::PATH_UNIX);
|
||||||
|
URI uri1(path1);
|
||||||
|
assert (uri1.toString() == "file:///var/www/site/index.html");
|
||||||
|
|
||||||
|
Path path2("/var/www/site/with space.html", Path::PATH_UNIX);
|
||||||
|
URI uri2(path2);
|
||||||
|
assert (uri2.toString() == "file:///var/www/site/with%20space.html");
|
||||||
|
|
||||||
|
Path path3("c:\\www\\index.html", Path::PATH_WINDOWS);
|
||||||
|
URI uri3(path3);
|
||||||
|
assert (uri3.toString() == "file:///c:/www/index.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void URITest::setUp()
|
void URITest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -797,6 +815,7 @@ CppUnit::Test* URITest::suite()
|
|||||||
CppUnit_addTest(pSuite, URITest, testSwap);
|
CppUnit_addTest(pSuite, URITest, testSwap);
|
||||||
CppUnit_addTest(pSuite, URITest, testEncodeDecode);
|
CppUnit_addTest(pSuite, URITest, testEncodeDecode);
|
||||||
CppUnit_addTest(pSuite, URITest, testOther);
|
CppUnit_addTest(pSuite, URITest, testOther);
|
||||||
|
CppUnit_addTest(pSuite, URITest, testFromPath);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ public:
|
|||||||
void testSwap();
|
void testSwap();
|
||||||
void testEncodeDecode();
|
void testEncodeDecode();
|
||||||
void testOther();
|
void testOther();
|
||||||
|
void testFromPath();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
Reference in New Issue
Block a user