예제 #1
0
        public void initially_Current_and_next_have_the_default_value()
        {
            LookAheadEnumerator <char> testing = CreateEnumerator("abc");

            Assert.AreEqual(default(char), testing.Current, "Current");
            Assert.AreEqual(default(char), testing.Next, "Next");
        }
            private IEnumerable <char> normalizeWhitespaces(IEnumerable <char> stream)
            {
                using (var enumerator = LookAheadEnumerator <char> .Create(stream))
                {
                    while (enumerator.MoveNext())
                    {
                        var current = enumerator.Current;

                        if (char.IsWhiteSpace(current))
                        {
                            char peeked;

                            if (enumerator.Peek(out peeked) &&
                                !char.IsWhiteSpace(peeked))
                            {
                                yield return(whitespace);
                            }
                        }
                        else
                        {
                            yield return(char.ToLowerInvariant(current));
                        }
                    }
                }
            }
예제 #3
0
        public void when_moving_to_last_entry_next_is_default()
        {
            LookAheadEnumerator <char> testing = CreateEnumerator("a");

            Assert.IsTrue(testing.MoveNext());
            Assert.AreEqual('a', testing.Current, "Current");
            Assert.AreEqual(default(char), testing.Next, "Next");
        }
예제 #4
0
        public void calling_movenext_sets_current_and_next()
        {
            LookAheadEnumerator <char> testing = CreateEnumerator("abc");

            Assert.IsTrue(testing.MoveNext());
            Assert.AreEqual('a', testing.Current, "Current");
            Assert.AreEqual('b', testing.Next, "Next");
        }
예제 #5
0
        public void when_at_the_end_both_current_and_next_are_default()
        {
            LookAheadEnumerator <char> testing = CreateEnumerator("a");

            Assert.IsTrue(testing.MoveNext());
            Assert.IsFalse(testing.MoveNext());
            Assert.AreEqual(default(char), testing.Current, "Current");
            Assert.AreEqual(default(char), testing.Next, "Next");
        }
예제 #6
0
        public void can_move_to_second_item()
        {
            LookAheadEnumerator <char> testing = CreateEnumerator("abc");

            Assert.IsTrue(testing.MoveNext());
            Assert.IsTrue(testing.MoveNext());
            Assert.AreEqual('b', testing.Current, "Current");
            Assert.AreEqual('c', testing.Next, "Next");
        }
            private string removePunctuationSymbols(IEnumerable <char> stream)
            {
                var builder = new StringBuilder();

                using (var enumerator = LookAheadEnumerator <char> .Create(stream))
                {
                    var apostropheSuffix = false;

                    while (enumerator.MoveNext())
                    {
                        var  current = enumerator.Current;
                        char peeked;

                        if (char.IsWhiteSpace(current))
                        {
                            apostropheSuffix = false;

                            if (enumerator.Peek(out peeked) &&
                                !char.IsWhiteSpace(peeked))
                            {
                                builder.Append(current);
                            }
                        }
                        else if (!apostropheSuffix)
                        {
                            if (char.IsPunctuation(current))
                            {
                                if (current == apostrophe)
                                {
                                    apostropheSuffix = true;
                                }
                                else
                                {
                                    if (enumerator.Peek(out peeked) &&
                                        !char.IsWhiteSpace(peeked) &&
                                        !char.IsPunctuation(peeked))
                                    {
                                        builder.Append(whitespace);
                                    }

                                    apostropheSuffix = false;
                                }
                            }
                            else if (char.IsDigit(current))
                            {
                                if (enumerator.Peek(out peeked))
                                {
                                    if (!char.IsDigit(peeked) &&
                                        !char.IsWhiteSpace(peeked))
                                    {
                                        builder.Append(current);
                                        builder.Append(whitespace);
                                    }
                                }
                                else
                                {
                                    builder.Append(current);
                                }
                            }
                            else
                            {
                                builder.Append(current);
                            }
                        }
                    }
                }

                return(builder.ToString());
            }
 internal LookAheadableValue(T value, LookAheadEnumerator <T> enumerator)
 {
     _Value      = value;
     _Enumerator = enumerator;
 }