Beispiel #1
0
        /// <summary>
        ///   Reads the number of syllables for the line from the supplied <see cref="TextReader" />
        /// </summary>
        /// <param name="input"> The <see cref="TextReader" /> object to use </param>
        public void ReadFrom(TextReader input)
        {
            var tokens        = new WordTokenizer(input).GetTokens();
            var syllableTotal = 0;

            var separator = string.Empty;

            var errorString = string.Format("The supplied text does not fit {0} syllables", Syllables);

            foreach (var token in tokens)
            {
                var sanitizedToken = WordTokenizer.Sanitize(token);
                var syllableCount  = new SyllableAnalyzer(sanitizedToken).GetCount();
                if (syllableTotal + syllableCount > Syllables)
                {
                    throw new ArgumentException(errorString, "input");
                }
                syllableTotal += syllableCount;
                Text          += separator + token.RemoveDigits();

                separator = " ";

                if (syllableTotal == Syllables)
                {
                    return;
                }
            }

            throw new ArgumentException(errorString, "input");
        }
Beispiel #2
0
        /// <summary>
        ///   Reads the number of syllables for the line from the supplied <see cref="TextReader" />
        /// </summary>
        /// <param name="input"> The <see cref="TextReader" /> object to use </param>
        public void ReadFrom(TextReader input)
        {
            var tokens = new WordTokenizer(input).GetTokens();
            var syllableTotal = 0;

            var separator = string.Empty;

            var errorString = string.Format("The supplied text does not fit {0} syllables", Syllables);

            foreach (var token in tokens)
            {
                var sanitizedToken = WordTokenizer.Sanitize(token);
                var syllableCount = new SyllableAnalyzer(sanitizedToken).GetCount();
                if (syllableTotal + syllableCount > Syllables)
                {
                    throw new ArgumentException(errorString, "input");
                }
                syllableTotal += syllableCount;
                Text += separator + token.RemoveDigits();

                separator = " ";

                if (syllableTotal == Syllables)
                {
                    return;
                }
            }

            throw new ArgumentException(errorString, "input");
        }