2020-09-21 19:22:45 +03:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2020-09-21 19:22:45 +03:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <regex>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
// URI stuff.
|
|
|
|
const static std::string pctEncoded = "(?:%[0-9a-fA-F][0-9a-fA-F])";
|
2023-12-12 18:22:54 +02:00
|
|
|
const static std::string schemeNameRegex = "(?:[a-z][a-z0-9+.-]*)";
|
2021-03-16 19:51:17 +02:00
|
|
|
const static std::string ipv6AddressSegmentRegex = "[0-9a-fA-F:]+(?:%\\w+)?";
|
2020-12-05 16:33:16 +02:00
|
|
|
const static std::string ipv6AddressRegex = "(?:\\[" + ipv6AddressSegmentRegex + "\\]|" + ipv6AddressSegmentRegex + ")";
|
2020-09-21 19:22:45 +03: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 + "|[/? \"])*";
|
2023-10-01 23:09:55 +03:00
|
|
|
const static std::string fragmentRegex = "(?:" + pcharRegex + "|[/? \"^])*";
|
2022-04-07 22:09:39 +03:00
|
|
|
const static std::string segmentRegex = "(?:" + pcharRegex + "*)";
|
2020-09-21 19:22:45 +03:00
|
|
|
const static std::string absPathRegex = "(?:(?:/" + segmentRegex + ")*/?)";
|
|
|
|
const static std::string pathRegex = "(?:" + segmentRegex + "(?:/" + segmentRegex + ")*/?)";
|
|
|
|
|
2023-03-27 04:12:25 +03:00
|
|
|
/// A Git ref (i.e. branch or tag name).
|
|
|
|
/// \todo check that this is correct.
|
2023-12-21 22:03:06 +02:00
|
|
|
/// This regex incomplete. See https://git-scm.com/docs/git-check-ref-format
|
2023-12-22 00:11:25 +02:00
|
|
|
const static std::string refRegexS = "[a-zA-Z0-9@][a-zA-Z0-9_.\\/@+-]*";
|
2020-09-21 19:22:45 +03:00
|
|
|
extern std::regex refRegex;
|
|
|
|
|
2023-03-27 04:12:25 +03: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 19:12:18 +03:00
|
|
|
/// See tests/functional/fetchGitRefs.sh for the full definition
|
2020-09-21 19:22:45 +03:00
|
|
|
const static std::string badGitRefRegexS = "//|^[./]|/\\.|\\.\\.|[[:cntrl:][:space:]:?^~\[]|\\\\|\\*|\\.lock$|\\.lock/|@\\{|[/.]$|^@$|^$";
|
|
|
|
extern std::regex badGitRefRegex;
|
|
|
|
|
2023-03-27 04:12:25 +03:00
|
|
|
/// A Git revision (a SHA-1 commit hash).
|
2020-09-21 19:22:45 +03:00
|
|
|
const static std::string revRegexS = "[0-9a-fA-F]{40}";
|
|
|
|
extern std::regex revRegex;
|
|
|
|
|
2023-03-27 04:12:25 +03:00
|
|
|
/// A ref or revision, or a ref followed by a revision.
|
2020-09-21 19:22:45 +03:00
|
|
|
const static std::string refAndOrRevRegex = "(?:(" + revRegexS + ")|(?:(" + refRegexS + ")(?:/(" + revRegexS + "))?))";
|
|
|
|
|
|
|
|
}
|