Read() public method

public Read ( ) : int
return int
Exemplo n.º 1
0
        internal static void GenerateContext(IDocumentBuilder builder,
                                             List<PositionTextPairGroup> groups,
                                             StreamReader _reader)
        {
            if (groups.Count == 0)
                return;

            builder.BeginContextBlock();

            PositionAwareStreamReader reader = new PositionAwareStreamReader(_reader.BaseStream, _reader.CurrentEncoding);
            PositionTextPairGroup prevGroup = null;

            foreach (PositionTextPairGroup group in groups)
            {
                char[] textBuf = new char[group.MaxChunkSize];
                long lastEnd = group.startPosition;
                int charsRead;

                reader.Seek(group.startPosition);

                if (prevGroup == null)
                {
                    if (groups.First().startPosition > 0)
                        builder.AddContextText("... ");
                }
                else if (group.startPosition != prevGroup.endPosition)
                    builder.AddContextText(" ... ");

                foreach (PositionTextPair pair in group.pairs.OrderBy(p => p.position))
                {
                    if (pair.position > lastEnd)
                    {
                        charsRead = reader.Read(textBuf, 0, (int)(pair.position - lastEnd));
                        lastEnd += charsRead;
                        builder.AddContextText(new string(textBuf, 0, charsRead));
                    }
                    charsRead = (int)reader.Read(textBuf, 0, pair.text.Length);
                    lastEnd += charsRead;
                    builder.AddContextText(new string(textBuf, 0, charsRead), TextStyle.Bold);
                }

                charsRead = reader.Read(textBuf, 0, (int)Math.Max(0, group.endPosition - lastEnd));
                builder.AddContextText(new string(textBuf, 0, charsRead));

                prevGroup = group;
            }

            if (!reader.EndOfStream)
                builder.AddContextText(" ...");

            builder.EndContextBlock();
        }
Exemplo n.º 2
0
        internal static void GenerateContext(IDocumentBuilder builder,
                                             List <PositionTextPairGroup> groups,
                                             StreamReader _reader)
        {
            if (groups.Count == 0)
            {
                return;
            }

            builder.BeginContextBlock();

            PositionAwareStreamReader reader    = new PositionAwareStreamReader(_reader.BaseStream, _reader.CurrentEncoding);
            PositionTextPairGroup     prevGroup = null;

            foreach (PositionTextPairGroup group in groups)
            {
                char[] textBuf = new char[group.MaxChunkSize];
                long   lastEnd = group.startPosition;
                int    charsRead;

                reader.Seek(group.startPosition);

                if (prevGroup == null)
                {
                    if (groups.First().startPosition > 0)
                    {
                        builder.AddContextText("... ");
                    }
                }
                else if (group.startPosition != prevGroup.endPosition)
                {
                    builder.AddContextText(" ... ");
                }


                foreach (PositionTextPair pair in group.pairs.OrderBy(p => p.position))
                {
                    if (pair.position > lastEnd)
                    {
                        charsRead = reader.Read(textBuf, 0, (int)(pair.position - lastEnd));
                        lastEnd  += charsRead;
                        builder.AddContextText(new string(textBuf, 0, charsRead));
                    }
                    charsRead = (int)reader.Read(textBuf, 0, pair.text.Length);
                    lastEnd  += charsRead;
                    builder.AddContextText(new string(textBuf, 0, charsRead), TextStyle.Bold);
                }

                charsRead = reader.Read(textBuf, 0, (int)Math.Max(0, group.endPosition - lastEnd));
                builder.AddContextText(new string(textBuf, 0, charsRead));

                prevGroup = group;
            }

            if (!reader.EndOfStream)
            {
                builder.AddContextText(" ...");
            }

            builder.EndContextBlock();
        }