Skip to content
Snippets Groups Projects
Commit 5e5f3401 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Allow relative file URIs

parent e8b9e32e
No related branches found
No related tags found
No related merge requests found
Pipeline #11768 failed
#include <ftl/uri.hpp> #include <ftl/uri.hpp>
// #include <filesystem> TODO When available
#include <cstdlib>
#include <unistd.h>
#include <loguru.hpp>
using ftl::URI; using ftl::URI;
using ftl::uri_t; using ftl::uri_t;
...@@ -27,13 +31,28 @@ URI::URI(const URI &c) { ...@@ -27,13 +31,28 @@ URI::URI(const URI &c) {
void URI::_parse(uri_t puri) { void URI::_parse(uri_t puri) {
UriUriA uri; UriUriA uri;
std::string suri = puri;
// NOTE: Non-standard additions to allow for Unix style relative file names.
if (suri[0] == '.') {
char cwdbuf[1024];
getcwd(cwdbuf, 1024);
suri = string("file://") + string(cwdbuf) + suri.substr(1);
} else if (suri[0] == '~') {
#ifdef WIN32
suri = string("file://") + string(std::getenv("HOMEDRIVE")) + string(std::getenv("HOMEPATH")) + suri.substr(1);
#else
suri = string("file://") + string(std::getenv("HOME")) + suri.substr(1);
#endif
}
#ifdef HAVE_URIPARSESINGLE #ifdef HAVE_URIPARSESINGLE
const char *errpos; const char *errpos;
if (uriParseSingleUriA(&uri, puri, &errpos) != URI_SUCCESS) { if (uriParseSingleUriA(&uri, puri, &errpos) != URI_SUCCESS) {
#else #else
UriParserStateA uris; UriParserStateA uris;
uris.uri = &uri; uris.uri = &uri;
if (uriParseUriA(&uris, puri) != URI_SUCCESS) { if (uriParseUriA(&uris, suri.c_str()) != URI_SUCCESS) {
#endif #endif
m_valid = false; m_valid = false;
m_host = "none"; m_host = "none";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment