AjTalk.ChunkReader.GetChunk C# (CSharp) Method

GetChunk() public method

public GetChunk ( ) : string
return string
        public string GetChunk()
        {
            if (this.closed)
                return null;

            TextWriter writer = new StringWriter();

            char lastch = (char)0;
            int ch = this.FirstChar();

            if (ch == -1)
            {
                this.reader.Close();
                this.closed = true;
                return null;
            }

            while (ch != -1)
            {
                if (ch == '!')
                {
                    if (this.reader.Peek() != '!')
                    {
                        if (lastch != 0)
                            break;
                    }
                    else
                        this.reader.Read();

                    writer.Write('!');
                    lastch = (char)ch;
                    ch = this.reader.Read();
                    continue;
                }

                if (ch == '\n' && lastch != '\r')
                    writer.Write('\r');
                else if (lastch == '\r' && ch != '\n')
                    writer.Write('\n');

                writer.Write((char)ch);
                lastch = (char)ch;
                ch = this.reader.Read();
            }

            if (ch != -1)
                while (this.reader.Peek() == '\r' || this.reader.Peek() == '\n')
                    this.reader.Read();

            writer.Close();
            return writer.ToString();
        }

Usage Example

Ejemplo n.º 1
0
 public void Process(ChunkReader reader, Machine machine, ICompiler compiler)
 {
     if (this.count > 0)
         for (int k = 0; k < this.count; k++)
             this.process(machine, compiler, reader.GetChunk());
     else
         for (string text = reader.GetChunk(); text != null; text = reader.GetChunk())
             if (string.IsNullOrEmpty(text.Trim()))
                 return;
             else
                 this.process(machine, compiler, text);
 }