1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00

isValidSchemeName: Add function

This commit is contained in:
Robert Hensing 2023-12-06 15:14:41 +01:00
parent 79eb2920bb
commit d3a85b6834
3 changed files with 44 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include "util.hh"
#include "split.hh"
#include "canon-path.hh"
#include "string.hh"
namespace nix {
@ -183,4 +184,20 @@ std::string fixGitURL(const std::string & url)
}
}
// https://www.rfc-editor.org/rfc/rfc3986#section-3.1
bool isValidSchemeName(std::string_view s)
{
if (s.empty()) return false;
if (!isASCIIAlpha(s[0])) return false;
for (auto c : s.substr(1)) {
if (isASCIIAlpha(c)) continue;
if (isASCIIDigit(c)) continue;
if (c == '+') continue;
if (c == '-') continue;
if (c == '.') continue;
return false;
}
return true;
}
}