diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 3510ad07..04a9bad3 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -443,6 +443,20 @@ string url_gpath(const string& url) return path_canon(url.substr(colon+1)); } +// Convert to file path if url is like file:// +string fileurltolocalpath(string url) +{ + if (url.find("file://") == 0) + url = url.substr(7, string::npos); + else + return string(); + string::size_type pos; + if ((pos = url.find_last_of("#")) != string::npos) { + url.erase(pos); + } + return url; +} + // Printable url: this is used to transcode from the system charset // into either utf-8 if transcoding succeeds, or url-encoded bool printableUrl(const string &fcharset, const string &in, string &out) diff --git a/src/utils/pathut.h b/src/utils/pathut.h index c405cfec..7b976373 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -55,6 +55,8 @@ extern string url_encode(const string& url, /// Transcode to utf-8 if possible or url encoding, for display. extern bool printableUrl(const string &fcharset, const string &in, string &out); +// Convert to file path if url is like file:// +extern string fileurltolocalpath(string url); /// Return the host+path part of an url. This is not a general /// routine, it does the right thing only in the recoll context