51 string stripPrefixes(
string urn,
bool strict) {
61 transform(lowered.begin(), lowered.end(), lowered.begin(), ::tolower);
66 if (strict && (numAts > 1 || !hasPrefix))
67 throw LSST_EXCEPT(BadNameError, (
"URN must start with \"urn:eupspkg:\" or \"@urn:eupspkg:\""));
82 void splitAndValidate(
const string& urn,
vector<string>& a,
bool strict) {
84 string stripped = stripPrefixes(urn, strict);
88 size_t i = stripped.
find(
":");
89 if (i == string::npos) {
94 stripped = stripped.
substr(i + 1);
102 throw LSST_EXCEPT(BadNameError,
"Wrong number of terms in policy file urn \"" + urn +
"\". " +
103 "The expected form is " +
104 "@urn:eupspkg:<product>:[<repository>:]<file> or " +
105 "@@<product>:[<repository>:]<file>. " +
106 "Is there a typo in the urn?");
117 splitAndValidate(urn, split, strictUrn);
129 splitAndValidate(urn, split, strictUrn);
141 splitAndValidate(urn, split, strictUrn);
142 if (split.
size() == 3)
158 transform(lc.begin(), lc.end(), lc.begin(), ::tolower);
159 while (lc[0] ==
'@') lc = lc.substr(1);
162 const string& stripped = stripPrefixes(s, strict);
static const std::string URN_PREFIX_ABBREV
The prefix that a Policy URN starts with.
static const std::string URN_PREFIX
The prefix that a Policy URN starts with.
static std::string productNameFromUrn(const std::string &urn, bool strictUrn=false)
Extract the product name from a URN.
static bool looksLikeUrn(const std::string &s, bool strict=false)
Does s look like a URN? That is, does it start with URN_PREFIX or URN_PREFIX_ABBREV?
static std::string reposFromUrn(const std::string &urn, bool strictUrn=false)
Extract the repository name from a URN, or "" if none.
#define LSST_EXCEPT(type,...)
static std::string filePathFromUrn(const std::string &urn, bool strictUrn=false)
Extract the local file path from a URN.
the definition of the UrnPolicyFile class