blob: 901655b19ef082745fd39cf371f97584adb71638 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// file : bpkg/manifest-utility.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <bpkg/manifest-utility>
#include <bpkg/diagnostics>
using namespace std;
namespace bpkg
{
package_scheme
parse_package_scheme (const char*& s)
{
// Ignore the character case for consistency with a case insensitivity of
// URI schemes some of which we may support in the future.
//
if (casecmp (s, "sys:", 4) == 0)
{
s += 4;
return package_scheme::sys;
}
return package_scheme::none;
}
string
parse_package_name (const char* s)
{
using traits = string::traits_type;
size_t n (traits::length (s));
if (const char* p = traits::find (s, n, '/'))
n = static_cast<size_t> (p - s);
if (n == 0)
fail << "empty package name in '" << s << "'";
return string (s, n);
}
version
parse_package_version (const char* s)
{
using traits = string::traits_type;
if (const char* p = traits::find (s, traits::length (s), '/'))
{
if (*++p == '\0')
fail << "empty package version in '" << s << "'";
try
{
return version (p);
}
catch (const invalid_argument& e)
{
fail << "invalid package version '" << p << "': " << e.what ();
}
}
return version ();
}
repository_location
parse_location (const char* s)
try
{
repository_location rl (s, repository_location ());
if (rl.relative ()) // Throws if the location is empty.
rl = repository_location (
dir_path (s).complete ().normalize ().string ());
return rl;
}
catch (const invalid_argument& e)
{
fail << "invalid repository location '" << s << "': " << e.what () << endf;
}
}
|