From 100436dee92677c03556716c4b2c1f3e43bc9328 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 3 Mar 2018 17:46:09 +0200 Subject: Use butl::url::traits::find() to sens URLs --- bpkg/manifest-utility.cxx | 7 ++++--- bpkg/pkg-build.cxx | 29 ++++++++++++----------------- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'bpkg') diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index 7b039c9..77baafb 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -4,6 +4,7 @@ #include +#include #include #include @@ -148,10 +149,10 @@ namespace bpkg { size_t p (s.find (':')); - // If it has no scheme or starts with the URL scheme (followed by :/) then - // this is not a canonical name. + // If it has no scheme or the scheme looks like that of a URL, then this + // is not a canonical name. // - if (p == string::npos || s[p + 1] == '/') + if (p == string::npos || butl::url::traits::find (s, p) != string::npos) return false; // This is a canonical name if the scheme is convertible to the repository diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 77469f5..49b027b 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -11,6 +11,8 @@ #include // cout #include // find(), find_if() +#include + #include #include #include @@ -1074,39 +1076,32 @@ namespace bpkg info << "run 'bpkg help pkg-build' for more information"; // Check if the argument has the []@ form or looks - // like a URL (the first colon is followed by "//"). Return the position - // of if that's the case and string::npos otherwise. + // like a URL. Return the position of if that's the case and + // string::npos otherwise. // // Note that we consider '@' to be such a delimiter only if it comes - // before "://" (think a URL which could contain its own '@'). + // before ":/" (think a URL which could contain its own '@'). // auto location = [] (const string& arg) -> size_t { - size_t p (0); + using url_traits = butl::url::traits; - // Check that the scheme belongs to a URL: is not one character long and - // is followed by :/. - // - auto url_scheme = [&arg, &p] () -> bool - { - assert (arg[p] == ':'); - return p > 1 && // Is not a Windows drive letter. - arg[p + 1] == '/'; - }; + size_t p (0); // Skip leading ':' that are not part of a URL. // while ((p = arg.find_first_of ("@:", p)) != string::npos && - arg[p] == ':' && !url_scheme ()) + arg[p] == ':' && + url_traits::find (arg, p) == string::npos) ++p; if (p != string::npos) { if (arg[p] == ':') { - p = url_scheme () - ? 0 // The whole thing is the location. - : string::npos; + // The whole thing must be the location. + // + p = url_traits::find (arg, p) == 0 ? 0 : string::npos; } else p += 1; // Skip '@'. -- cgit v1.1