/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text, options and prefix. /// </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> /// <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 WordParser(string text, WordParserOptions options, char prefix) { if (options is < WordParserOptions.None or > (WordParserOptions.IgnoreMnemonicsIndicators | WordParserOptions.SplitCompoundWords)) { throw new ArgumentException($"'{(int)options}' is invalid for enum type '{nameof(WordParserOptions)}'", nameof(options)); } _text = text ?? throw new ArgumentNullException(nameof(text)); _options = options; _buffer = new StringBuilder(text.Length); _prefix = prefix; }
internal static Collection <string> Parse(string text, WordParserOptions options, char prefix) { string str; WordParser parser = new WordParser(text, options, prefix); Collection <string> collection = new Collection <string>(); while ((str = parser.NextWord()) != null) { collection.Add(str); } return(collection); }
/// <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> internal static Collection <string> Parse(string text, WordParserOptions options, char prefix) { WordParser parser = new WordParser(text, options, prefix); Collection <string> words = new Collection <string>(); string?word; while ((word = parser.NextWord()) != null) { words.Add(word); } return(words); }
internal WordParser(string text, WordParserOptions options, char prefixChar) { if (text == null) { throw new ArgumentNullException("text"); } if ((options < WordParserOptions.None) || (options > (WordParserOptions.SplitCompoundWords | WordParserOptions.IgnoreMnemonicsIndicators))) { throw new InvalidEnumArgumentException("options", (int)options, typeof(WordParserOptions)); } this.text = text; this.wordParserOptions = options; this.buffer = new StringBuilder(text.Length); this.prefixChar = prefixChar; }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text, options and prefix. /// </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> /// <exception cref="ArgumentNullException"> /// <paramref name="text"/> is <see langword="null"/>. /// </exception> /// <exception cref="InvalidEnumArgumentException"> /// <paramref name="options"/> is not one or more of the <see cref="WordParserOptions"/> values. /// </exception> internal WordParser(string text, WordParserOptions options, char prefix) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (options < WordParserOptions.None || options > (WordParserOptions.IgnoreMnemonicsIndicators | WordParserOptions.SplitCompoundWords)) { throw new InvalidEnumArgumentException(nameof(options), (int)options, typeof(WordParserOptions)); } _text = text; _options = options; _buffer = new StringBuilder(text.Length); _prefix = prefix; }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text, options and prefix. /// </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> /// <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 WordParser(string text, WordParserOptions options, char prefix) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (options < WordParserOptions.None || options > (WordParserOptions.IgnoreMnemonicsIndicators | WordParserOptions.SplitCompoundWords)) { throw new ArgumentException($"'{nameof(options)}' ({((int)options).ToString()}) is invalid for Enum type'{typeof(WordParserOptions).Name}'"); } _text = text; _options = options; _buffer = new StringBuilder(text.Length); _prefix = prefix; }
/// <summary> /// Returns a value indicating whether at least one of the specified words occurs, using a case-insensitive ordinal comparision, 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="InvalidEnumArgumentException"> /// <paramref name="options"/> is not one or more of the <see cref="WordParserOptions"/> values. /// </exception> internal static bool ContainsWord(string text, WordParserOptions options, char prefix, params string[] words) { if (words == null) { throw new ArgumentNullException("words"); } WordParser parser = new WordParser(text, options, prefix); string parsedWord; while ((parsedWord = parser.NextWord()) != null) { foreach (string word in words) { if (string.Equals(parsedWord, word, StringComparison.OrdinalIgnoreCase)) { return(true); } } } return(false); }
/// <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> internal static bool ContainsWord(string text, WordParserOptions options, char prefix, ImmutableArray <string> words) { if (words.IsDefault) { throw new ArgumentNullException(nameof(words)); } WordParser parser = new WordParser(text, options, prefix); string?parsedWord; while ((parsedWord = parser.NextWord()) != null) { foreach (string word in words) { if (string.Equals(parsedWord, word, StringComparison.OrdinalIgnoreCase)) { return(true); } } } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class. /// </summary> /// <param name="text"> /// The text. /// </param> /// <param name="options"> /// The options. /// </param> public WordParser(string text, WordParserOptions options) : this(text, options, '\0') { }
/// <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> /// <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> internal static Collection <string> Parse(string text, WordParserOptions options) { return(Parse(text, options, NullChar)); }
/// <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="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, params string[] words) { return(ContainsWord(text, options, NullChar, words)); }
internal static bool ContainsWord(string text, WordParserOptions options, params string[] words) { return(ContainsWord(text, options, '\0', words)); }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text and 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> /// <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 WordParser(string text, WordParserOptions options) : this(text, options, NullChar) { }
/// <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> /// <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> internal static Collection<string> Parse(string text, WordParserOptions options) { return Parse(text, options, NullChar); }
internal static Collection<string> Parse(string text, WordParserOptions options, char prefix) { string str; WordParser parser = new WordParser(text, options, prefix); Collection<string> collection = new Collection<string>(); while ((str = parser.NextWord()) != null) { collection.Add(str); } return collection; }
/// <summary> /// The parse. /// </summary> /// <param name="text"> /// The text. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// The System.Collections.ObjectModel.Collection. /// </returns> public static Collection<string> Parse(string text, WordParserOptions options) { return Parse(text, options, '\0'); }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class. /// </summary> /// <param name="text"> /// The text. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="recognizedWords"> /// The recognized words. /// </param> public WordParser(string text, WordParserOptions options, ICollection<string> recognizedWords) : this(text, options, recognizedWords, '\0') { }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class. /// </summary> /// <param name="text"> /// The text. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="recognizedWords"> /// The recognized words. /// </param> public WordParser(string text, WordParserOptions options, ICollection <string> recognizedWords) : this(text, options, recognizedWords, '\0') { }
/// <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="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, ImmutableArray <string> words) { return(ContainsWord(text, options, NullChar, 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="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> internal static bool ContainsWord(string text, WordParserOptions options, params string[] words) { return ContainsWord(text, options, NullChar, words); }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text and 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> /// <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> internal WordParser(string text, WordParserOptions options) : this(text, options, NullChar) { }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text, options and prefix. /// </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> /// <exception cref="ArgumentNullException"> /// <paramref name="text"/> is <see langword="null"/>. /// </exception> /// <exception cref="InvalidEnumArgumentException"> /// <paramref name="options"/> is not one or more of the <see cref="WordParserOptions"/> values. /// </exception> internal WordParser(string text, WordParserOptions options, char prefix) { if (text == null) { throw new ArgumentNullException("text"); } if (options < WordParserOptions.None || options > (WordParserOptions.IgnoreMnemonicsIndicators | WordParserOptions.SplitCompoundWords)) { throw new InvalidEnumArgumentException("options", (int)options, typeof(WordParserOptions)); } _text = text; _options = options; _buffer = new StringBuilder(text.Length); _prefix = prefix; }
/// <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> internal static Collection<string> Parse(string text, WordParserOptions options, char prefix) { WordParser parser = new WordParser(text, options, prefix); Collection<string> 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> internal static bool ContainsWord(string text, WordParserOptions options, char prefix, params string[] words) { if (words == null) { throw new ArgumentNullException(nameof(words)); } WordParser parser = new WordParser(text, options, prefix); string parsedWord; while ((parsedWord = parser.NextWord()) != null) { foreach (string word in words) { if (string.Equals(parsedWord, word, StringComparison.OrdinalIgnoreCase)) { return true; } } } return false; }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text and 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> /// <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 WordParser(string text, WordParserOptions options) : this(text, options, NullChar) { }
/// <summary> /// Initializes a new instance of the <see cref="WordParser"/> class with the specified text, options and prefix. /// </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> /// <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> internal WordParser(string text, WordParserOptions options, char prefix) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (options < WordParserOptions.None || options > (WordParserOptions.IgnoreMnemonicsIndicators | WordParserOptions.SplitCompoundWords)) { throw new ArgumentException($"'{nameof(options)}' ({((int)options).ToString()}) is invalid for Enum type'{typeof(WordParserOptions).Name}'"); } _text = text; _options = options; _buffer = new StringBuilder(text.Length); _prefix = prefix; }
/// <summary> /// The parse. /// </summary> /// <param name="text"> /// The text. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// The System.Collections.ObjectModel.Collection. /// </returns> public static Collection <string> Parse(string text, WordParserOptions options) { return(Parse(text, options, '\0')); }