in sources/Google.Solutions.Platform/Net/ChromePolicyUrlPattern.cs [103:167]
public static ChromePolicyUrlPattern Parse(string pattern)
{
Precondition.ExpectNotEmpty(pattern, nameof(pattern));
pattern = pattern.ToLower();
if (pattern == All)
{
return new ChromePolicyUrlPattern(
null, // All schemes.
null, // All ports.
null, // All domains.
true); // All subdomains.
}
var colonDoubleSlashIndex = pattern.IndexOf("://");
string? scheme;
string patternWithoutScheme;
if (colonDoubleSlashIndex == -1)
{
scheme = null;
patternWithoutScheme = pattern;
}
else if (colonDoubleSlashIndex == 1 && pattern[0] == '*')
{
scheme = null;
patternWithoutScheme = pattern.Substring(4);
}
else
{
scheme = pattern.Substring(0, colonDoubleSlashIndex);
patternWithoutScheme = pattern.Substring(colonDoubleSlashIndex + 3);
}
var slashIndex = patternWithoutScheme.IndexOf('/');
var domainAndPort = slashIndex >= 0
? patternWithoutScheme.Substring(0, slashIndex)
: patternWithoutScheme;
var ipv6endBracket = domainAndPort.IndexOf(']');
var colonIndex = domainAndPort.IndexOf(':', ipv6endBracket + 1);
var port = colonIndex >= 0
? domainAndPort.Substring(colonIndex + 1) == "*"
? null
: (ushort?)ushort.Parse(domainAndPort.Substring(colonIndex + 1))
: DefaultPortForScheme(scheme);
var domain = colonIndex >= 0
? domainAndPort.Substring(0, colonIndex)
: domainAndPort;
if (string.IsNullOrEmpty(domain))
{
throw new ArgumentException("Pattern is empty", nameof(pattern));
}
var includeSubdomains = domain.StartsWith(SubdomainWilcard);
return new ChromePolicyUrlPattern(
scheme,
port,
includeSubdomains
? domain.Substring(SubdomainWilcard.Length)
: domain,
includeSubdomains);
}