aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-03 17:46:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-03 17:46:09 +0200
commit100436dee92677c03556716c4b2c1f3e43bc9328 (patch)
tree74c9a976ec1a28878ac54d9b625c68d11b4b9576
parent646767a35fb2b9b0e3f992a3092c761ea6e5e362 (diff)
Use butl::url::traits::find() to sens URLs
-rw-r--r--bpkg/manifest-utility.cxx7
-rw-r--r--bpkg/pkg-build.cxx29
2 files changed, 16 insertions, 20 deletions
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 <bpkg/manifest-utility.hxx>
+#include <libbutl/url.mxx>
#include <libbutl/sha256.mxx>
#include <bpkg/diagnostics.hxx>
@@ -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 <iostream> // cout
#include <algorithm> // find(), find_if()
+#include <libbutl/url.mxx>
+
#include <bpkg/package.hxx>
#include <bpkg/package-odb.hxx>
#include <bpkg/database.hxx>
@@ -1074,39 +1076,32 @@ namespace bpkg
info << "run 'bpkg help pkg-build' for more information";
// Check if the argument has the [<packages>]@<location> form or looks
- // like a URL (the first colon is followed by "//"). Return the position
- // of <location> if that's the case and string::npos otherwise.
+ // like a URL. Return the position of <location> 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 '@'.