/// <summary> /// Attempts to read one of many strings from the parser and if it succeeds removes the string from the parsers buffer. /// </summary> /// <param name="parser">A parser on which to operate.</param> /// <param name="matched">The actual string that was matched.</param> /// <param name="comparer">The comparer to work with to match the strings, defaults to <see cref="StringComparer.Ordinal" />.</param> /// <param name="expect">A list of strings to check again, in order.</param> /// <returns>True, if the buffer would return <paramref name="expect"/> next, false otherwise.</returns> public static bool TryRead(this ITextParser parser, [MaybeNullWhen(false)] out ParserString matched, IEqualityComparer <string?>?comparer, params object[] expected) { matched = null; foreach (var o in expected) { var str = o?.ToString(); if (str != null && parser.StartsWith(str, out str, comparer)) { matched = parser.Read(str.Length); return(true); } } return(false); }