Beispiel #1
0
        /// <summary>
        /// Get if this match can be found in a stack
        /// </summary>
        /// <param name="stack">List of strings to search for the given content</param>
        /// <returns>Tuple of success and matched item</returns>
        public (bool, string) Match(IEnumerable <string> stack)
        {
            // If either array is null or empty, we can't do anything
            if (stack == null || !stack.Any() || Needle == null || Needle.Length == 0)
            {
                return(false, null);
            }

            // Preprocess the needle, if necessary
            string procNeedle = MatchExact ? Needle : Needle.ToLowerInvariant();

            foreach (string stackItem in stack)
            {
                // Preprocess the stack item, if necessary
                string procStackItem = MatchExact ? stackItem : stackItem.ToLowerInvariant();

                if (UseEndsWith && procStackItem.EndsWith(procNeedle))
                {
                    return(true, stackItem);
                }
                else if (!UseEndsWith && procStackItem.Contains(procNeedle))
                {
                    return(true, stackItem);
                }
            }

            return(false, null);
        }