Extract and expose splitUriAndParams function

which splits a URL into localtor and parameter parts
This commit is contained in:
Dzmitry Zaitsau 2019-02-21 11:44:25 +01:00
parent 6bfb082ea2
commit 07f992a74b
2 changed files with 16 additions and 4 deletions

View file

@ -842,12 +842,11 @@ namespace nix {
RegisterStoreImplementation::Implementations * RegisterStoreImplementation::implementations = 0; RegisterStoreImplementation::Implementations * RegisterStoreImplementation::implementations = 0;
/* Split URI into protocol+hierarchy part and its parameter set. */
ref<Store> openStore(const std::string & uri_, std::pair<std::string, Store::Params> splitUriAndParams(const std::string & uri_)
const Store::Params & extraParams)
{ {
auto uri(uri_); auto uri(uri_);
Store::Params params(extraParams); Store::Params params;
auto q = uri.find('?'); auto q = uri.find('?');
if (q != std::string::npos) { if (q != std::string::npos) {
for (auto s : tokenizeString<Strings>(uri.substr(q + 1), "&")) { for (auto s : tokenizeString<Strings>(uri.substr(q + 1), "&")) {
@ -873,6 +872,15 @@ ref<Store> openStore(const std::string & uri_,
} }
uri = uri_.substr(0, q); uri = uri_.substr(0, q);
} }
return {uri, params};
}
ref<Store> openStore(const std::string & uri_,
const Store::Params & extraParams)
{
auto [uri, uriParams] = splitUriAndParams(uri_);
auto params = extraParams;
params.insert(uriParams.begin(), uriParams.end());
for (auto fun : *RegisterStoreImplementation::implementations) { for (auto fun : *RegisterStoreImplementation::implementations) {
auto store = fun(uri, params); auto store = fun(uri, params);

View file

@ -798,4 +798,8 @@ ValidPathInfo decodeValidPathInfo(std::istream & str,
for paths created by makeFixedOutputPath() / addToStore(). */ for paths created by makeFixedOutputPath() / addToStore(). */
std::string makeFixedOutputCA(bool recursive, const Hash & hash); std::string makeFixedOutputCA(bool recursive, const Hash & hash);
/* Split URI into protocol+hierarchy part and its parameter set. */
std::pair<std::string, Store::Params> splitUriAndParams(const std::string & uri);
} }