mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
Poco::URI: added new constructor to create URI from Path
This commit is contained in:
parent
102413aed5
commit
50f1f12cab
@ -27,6 +27,9 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Path;
|
||||
|
||||
|
||||
class Foundation_API URI
|
||||
/// 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
|
||||
/// 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();
|
||||
/// Destroys the URI.
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/Path.h"
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
@ -14,9 +14,11 @@
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/Path.h"
|
||||
|
||||
|
||||
using Poco::URI;
|
||||
using Poco::Path;
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
@ -797,6 +815,7 @@ CppUnit::Test* URITest::suite()
|
||||
CppUnit_addTest(pSuite, URITest, testSwap);
|
||||
CppUnit_addTest(pSuite, URITest, testEncodeDecode);
|
||||
CppUnit_addTest(pSuite, URITest, testOther);
|
||||
CppUnit_addTest(pSuite, URITest, testFromPath);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
void testSwap();
|
||||
void testEncodeDecode();
|
||||
void testOther();
|
||||
void testFromPath();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user