1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-28 13:11:00 +01:00

isValidSchemeName: Use regex

As requested by Eelco Dolstra. I think it used to be simpler.

(cherry picked from commit 4eaeda6604)
This commit is contained in:
Robert Hensing 2023-12-12 17:43:54 +01:00
parent 598b0e2317
commit ebdb6926fd
2 changed files with 8 additions and 12 deletions

View file

@ -2,7 +2,6 @@
#include "url-parts.hh"
#include "util.hh"
#include "split.hh"
#include "string.hh"
namespace nix {
@ -179,17 +178,9 @@ 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;
static std::regex regex(schemeNameRegex, std::regex::ECMAScript);
return std::regex_match(s.begin(), s.end(), regex, std::regex_constants::match_default);
}
}