public static bool MatchFullName()

in src/common/details/named_values/parsers/named_value_token_parser_helpers.cs [26:86]


        public static bool MatchFullName(string fullName, INamedValueTokens tokens, INamedValues values, string partsRequired, out int nameTokenCount)
        {
            nameTokenCount = 0;

            // Break the "FullName" into parts, some of which will be required, some of which are optional
            var prefix = tokens.NamePrefixRequired();
            var fullNameParts = fullName.Split('.');
            var fullNamePartsOk = fullNameParts.Length == partsRequired.Length;

            // Break the first token into parts, so we can start checking it
            var iPeekToken = 0;
            var token = tokens.PeekNextToken(iPeekToken);
            var tokenParts = token != null ? new List<string>(token.Split('.')) : new List<string>();
            var iTokenPart = 0;

            // For each FullName "part", check to see if it matches the next token "part" and check if that FullName part was required or not
            for (int iNamePart = 0; fullNamePartsOk && iNamePart < fullNameParts.Length; iNamePart++)
            {
                // Do they match?
                var tokenPart = tokenParts.Count > iTokenPart ? tokenParts[iTokenPart] : null;
                var fullNamePart = prefix + fullNameParts[iNamePart];
                var fullNamePartWild = fullNamePart == "*";
                var partsMatch = tokenPart != null && (fullNamePartWild || tokenPart.Equals(fullNamePart, StringComparison.InvariantCultureIgnoreCase));

                // If so, we'll increment the number of parts we've matched (which is also tracking the next token to use)
                if (partsMatch)
                {
                    iTokenPart += 1;
                    prefix = "";
                }

                // If we matched as a wildcard, keep track of the wildcard value
                if (partsMatch && fullNamePartWild)
                {
                    SetWild(values, fullNamePart, tokenPart);
                }

                // Check to see if they either matched, or if the name part was optional
                var namePartOptional = iNamePart < partsRequired.Length && partsRequired[iNamePart] == '0';
                var thisNamePartOk = partsMatch || namePartOptional;
                fullNamePartsOk = thisNamePartOk;

                if (!fullNamePartsOk) break; // didn't match... we're outta here...

                if (partsMatch && iTokenPart == tokenParts.Count) // fully matched all the token parts, skip to the next token
                {
                    iPeekToken += 1;
                    token = tokens.PeekNextToken(iPeekToken);
                    tokenParts = token != null ? new List<string>(token.Split('.')) : new List<string>();
                    iTokenPart = 0;
                }
            }

            if (fullNamePartsOk && iPeekToken > 0)
            {
                nameTokenCount = iPeekToken;
                return true;
            }

            return false;
        }