Esempio n. 1
0
        /// <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;
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
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>
        /// <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);
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
        /// <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;
        }
Esempio n. 7
0
        /// <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;
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
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="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);
        }
Esempio n. 10
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>
 public WordParser(string text, WordParserOptions options)
     : this(text, options, '\0')
 {
 }
Esempio n. 11
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));
 }
Esempio n. 12
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, params string[] words)
 {
     return(ContainsWord(text, options, NullChar, words));
 }
Esempio n. 13
0
 internal static bool ContainsWord(string text, WordParserOptions options, params string[] words)
 {
     return(ContainsWord(text, options, '\0', words));
 }
Esempio n. 14
0
 /// <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)
 {
 }
Esempio n. 15
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);
 }
Esempio n. 16
0
        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;
        }
Esempio n. 17
0
 /// <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')
 {
 }
Esempio n. 19
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')
 {
 }
Esempio n. 20
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));
 }
Esempio n. 21
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>
 internal static bool ContainsWord(string text, WordParserOptions options, params string[] words)
 {
     return ContainsWord(text, options, NullChar, words);
 }
Esempio n. 22
0
 /// <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)
 {
 }
Esempio n. 23
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>
 public WordParser(string text, WordParserOptions options)
     : this(text, options, '\0')
 {
 }
Esempio n. 24
0
        /// <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;
        }
Esempio n. 25
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>
        /// <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;
        }
Esempio n. 26
0
 /// <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)
 {
 }
Esempio n. 27
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="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;
        }
Esempio n. 28
0
 /// <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)
 {
 }
Esempio n. 29
0
        /// <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;
        }
Esempio n. 30
0
 /// <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'));
 }