2020-09-21 16:22:45 +00:00
|
|
|
#pragma once
|
2023-04-01 03:18:41 +00:00
|
|
|
///@file
|
2020-09-21 16:22:45 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <regex>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
// URI stuff.
|
|
|
|
const static std::string pctEncoded = "(?:%[0-9a-fA-F][0-9a-fA-F])";
|
2020-10-05 15:53:30 +00:00
|
|
|
const static std::string schemeRegex = "(?:[a-z][a-z0-9+.-]*)";
|
2021-03-16 17:51:17 +00:00
|
|
|
const static std::string ipv6AddressSegmentRegex = "[0-9a-fA-F:]+(?:%\\w+)?";
|
2020-12-05 14:33:16 +00:00
|
|
|
const static std::string ipv6AddressRegex = "(?:\\[" + ipv6AddressSegmentRegex + "\\]|" + ipv6AddressSegmentRegex + ")";
|
2020-09-21 16:22:45 +00:00
|
|
|
const static std::string unreservedRegex = "(?:[a-zA-Z0-9-._~])";
|
|
|
|
const static std::string subdelimsRegex = "(?:[!$&'\"()*+,;=])";
|
|
|
|
const static std::string hostnameRegex = "(?:(?:" + unreservedRegex + "|" + pctEncoded + "|" + subdelimsRegex + ")*)";
|
|
|
|
const static std::string hostRegex = "(?:" + ipv6AddressRegex + "|" + hostnameRegex + ")";
|
|
|
|
const static std::string userRegex = "(?:(?:" + unreservedRegex + "|" + pctEncoded + "|" + subdelimsRegex + "|:)*)";
|
|
|
|
const static std::string authorityRegex = "(?:" + userRegex + "@)?" + hostRegex + "(?::[0-9]+)?";
|
|
|
|
const static std::string pcharRegex = "(?:" + unreservedRegex + "|" + pctEncoded + "|" + subdelimsRegex + "|[:@])";
|
|
|
|
const static std::string queryRegex = "(?:" + pcharRegex + "|[/? \"])*";
|
2022-04-07 19:09:39 +00:00
|
|
|
const static std::string segmentRegex = "(?:" + pcharRegex + "*)";
|
2020-09-21 16:22:45 +00:00
|
|
|
const static std::string absPathRegex = "(?:(?:/" + segmentRegex + ")*/?)";
|
|
|
|
const static std::string pathRegex = "(?:" + segmentRegex + "(?:/" + segmentRegex + ")*/?)";
|
|
|
|
|
2023-03-27 01:12:25 +00:00
|
|
|
/// A Git ref (i.e. branch or tag name).
|
|
|
|
/// \todo check that this is correct.
|
2024-03-04 06:27:52 +00:00
|
|
|
/// This regex incomplete. See https://git-scm.com/docs/git-check-ref-format
|
|
|
|
const static std::string refRegexS = "[a-zA-Z0-9@][a-zA-Z0-9_.\\/@+-]*";
|
2020-09-21 16:22:45 +00:00
|
|
|
extern std::regex refRegex;
|
|
|
|
|
2023-03-27 01:12:25 +00:00
|
|
|
/// Instead of defining what a good Git Ref is, we define what a bad Git Ref is
|
|
|
|
/// This is because of the definition of a ref in refs.c in https://github.com/git/git
|
2023-10-05 16:12:18 +00:00
|
|
|
/// See tests/functional/fetchGitRefs.sh for the full definition
|
2020-09-21 16:22:45 +00:00
|
|
|
const static std::string badGitRefRegexS = "//|^[./]|/\\.|\\.\\.|[[:cntrl:][:space:]:?^~\[]|\\\\|\\*|\\.lock$|\\.lock/|@\\{|[/.]$|^@$|^$";
|
|
|
|
extern std::regex badGitRefRegex;
|
|
|
|
|
2023-03-27 01:12:25 +00:00
|
|
|
/// A Git revision (a SHA-1 commit hash).
|
2020-09-21 16:22:45 +00:00
|
|
|
const static std::string revRegexS = "[0-9a-fA-F]{40}";
|
|
|
|
extern std::regex revRegex;
|
|
|
|
|
2023-03-27 01:12:25 +00:00
|
|
|
/// A ref or revision, or a ref followed by a revision.
|
2020-09-21 16:22:45 +00:00
|
|
|
const static std::string refAndOrRevRegex = "(?:(" + revRegexS + ")|(?:(" + refRegexS + ")(?:/(" + revRegexS + "))?))";
|
|
|
|
|
|
|
|
const static std::string flakeIdRegexS = "[a-zA-Z][a-zA-Z0-9_-]*";
|
|
|
|
extern std::regex flakeIdRegex;
|
|
|
|
|
|
|
|
}
|