internal static bool LineTryMatch(this Lines lines, int lineNo, Regex regex, out Match match, bool consume)
        {
            if (!lines.Any())
            {
                match = null;
                return(false);
            }

            if (lines.Count() < lineNo)
            {
                match = null;
                return(false);
            }

            var line = lines[lineNo];

            match = regex.Match(line);

            if (match.Success && consume)
            {
                lines.Consume(lineNo, match.Index, match.Length);
            }

            return(match.Success);
        }
Beispiel #2
0
        private int FindBestIndentationForFormControl(string matchOfFirstLine, Lines lines)
        {
            int result      = matchOfFirstLine.Length;
            var firstLine   = lines.First();
            int firstIndent = firstLine.Length - firstLine.TrimStart().Length;

            if (firstIndent < result)
            {
                result = firstIndent;
            }
            if (lines.Count() > 1)
            {
                var secondLine   = lines.Skip(1).First();
                int secondIndent = secondLine.Length - secondLine.TrimStart().Length;
                if (secondIndent < result)
                {
                    result = secondIndent;
                }
            }
            return(result);
        }
 internal static bool LastLineTryMatch(this Lines lines, Regex regex, out Match match, bool consume = true)
 {
     return(LineTryMatch(lines, lines.Count() - 1, regex, out match, consume));
 }
 internal static Match LastLineMustMatch(this Lines lines, Regex regex)
 {
     return(LineMustMatch(lines, lines.Count() - 1, regex));
 }