Пример #1
0
Файл: IO.cs Проект: sq/Libraries
            void _OnDecodeComplete(IFuture f)
            {
                if (Parent.IsDisposed)
                {
                    Result.Dispose();
                    return;
                }

                var e = f.Error;

                if (e != null)
                {
                    Buffer.Dispose();
                    Result.Fail(e);
                }
                else
                {
                    int numChars = (int)f.Result;

                    if (numChars > 0)
                    {
                        ProcessDecodedChars();
                    }
                    else
                    {
                        string resultString = Buffer.DisposeAndGetContents();
                        if (resultString.Length == 0)
                        {
                            resultString = null;
                        }

                        Result.Complete(resultString);
                    }
                }
            }
Пример #2
0
        public void TestBuildString()
        {
            var buffer = new CharacterBuffer();

            var s = "Some test string";

            for (int i = 0; i < s.Length; i++)
                buffer.Append(s[i]);

            Assert.AreEqual(buffer.DisposeAndGetContents(), s);
        }
Пример #3
0
        public void TestClear()
        {
            var buffer = new CharacterBuffer();

            buffer.Append('a');
            buffer.Append('b');

            buffer.Clear();

            buffer.Append('c');

            Assert.AreEqual(buffer.DisposeAndGetContents(), "c");
        }
Пример #4
0
Файл: IO.cs Проект: sq/Libraries
            public void ProcessDecodedChars()
            {
                if (Parent.ReadDecodedCharactersUntilSentinel(Buffer, '\n'))
                {
                    if ((Buffer.Length > 0) && (Buffer[Buffer.Length - 1] == '\r'))
                    {
                        Buffer.Remove(Buffer.Length - 1, 1);
                    }

                    if (Parent.EndOfStream)
                    {
                        Parent._ExtraLine = true;
                    }

                    var resultString = Buffer.DisposeAndGetContents();

                    Result.Complete(resultString);
                }
                else
                {
                    var decodeMoreChars = Parent.DecodeMoreData();
                    decodeMoreChars.RegisterOnComplete(OnDecodeComplete);
                }
            }