/// <summary> /// Returns the words contained in the specified text, delimiting based on the specified options. /// </summary> /// <param name="text"> /// A <see cref="string"/> containing the text to parse. /// </param> /// <param name="options"> /// One or more of the <see cref="WordParserOptions"/> specifying parsing and delimiting options. /// </param> /// <param name="prefix"> /// A <see cref="char"/> representing an optional prefix of <paramref name="text"/>, that if present, /// will be returned as a separate token. /// </param> /// <returns> /// A <see cref="Collection{T}"/> of strings containing the words contained in <paramref name="text"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="text"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="options"/> is not one or more of the <see cref="WordParserOptions"/> values. /// </exception> public static Collection <string> Parse(string text, WordParserOptions options, char prefix) { var parser = new WordParser(text, options, prefix); var words = new Collection <string>(); string word; while ((word = parser.NextWord()) != null) { words.Add(word); } return(words); }
/// <summary> /// Returns a value indicating whether at least one of the specified words occurs, using a case-insensitive ordinal comparison, within the specified text. /// </summary> /// <param name="text"> /// A <see cref="string"/> containing the text to check. /// </param> /// <param name="options"> /// One or more of the <see cref="WordParserOptions"/> specifying parsing and delimiting options. /// </param> /// <param name="prefix"> /// A <see cref="char"/> representing an optional prefix of <paramref name="text"/>, that if present, /// will be returned as a separate token. /// </param> /// <param name="words"> /// A <see cref="string"/> array containing the words to seek. /// </param> /// <returns> /// <see langword="true"/> if at least one of the elements within <paramref name="words"/> occurs within <paramref name="text"/>, otherwise, <see langword="false"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="text"/> is <see langword="null"/>. /// <para> /// -or- /// </para> /// <paramref name="words"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="options"/> is not one or more of the <see cref="WordParserOptions"/> values. /// </exception> public static bool ContainsWord(string text, WordParserOptions options, char prefix, ImmutableArray <string> words) { if (words.IsDefault) { throw new ArgumentNullException(nameof(words)); } var parser = new WordParser(text, options, prefix); string parsedWord; while ((parsedWord = parser.NextWord()) != null) { foreach (var word in words) { if (string.Equals(parsedWord, word, StringComparison.OrdinalIgnoreCase)) { return(true); } } } return(false); }