Ejemplo n.º 1
0
        public static object Getc(RubyIO /*!*/ self)
        {
            self.AssertOpenedForReading();
            int c = self.ReadByteNormalizeEoln();

            return((c != -1) ? ScriptingRuntimeHelpers.Int32ToObject(c) : null);
        }
Ejemplo n.º 2
0
        public static int ReadChar(RubyIO /*!*/ self)
        {
            self.AssertOpenedForReading();
            int c = self.ReadByteNormalizeEoln();

            if (c == -1)
            {
                throw new EOFError("end of file reached");
            }

            return(c);
        }
Ejemplo n.º 3
0
        public static MutableString /*!*/ Read(RubyIO /*!*/ self)
        {
            self.AssertOpenedForReading();

            if (!self.PreserveEndOfLines)
            {
                MutableString result = MutableString.CreateBinary();
                int           c;
                while ((c = self.ReadByteNormalizeEoln()) != -1)
                {
                    result.Append((byte)c);
                }
                return(result);
            }
            else
            {
                // TODO: change this once Binary mutable string uses resizable byte[] instead of List<byte>
                return(MutableString.CreateBinary(ReadAllBytes(self)));
            }
        }
Ejemplo n.º 4
0
        public static object EachByte(BlockParam block, RubyIO /*!*/ self)
        {
            self.AssertOpenedForReading();
            object aByte;

            while ((aByte = Getc(self)) != null)
            {
                if (block == null)
                {
                    throw RubyExceptions.NoBlockGiven();
                }

                object result;
                if (block.Yield((int)aByte, out result))
                {
                    return(result);
                }
            }
            return(self);
        }
Ejemplo n.º 5
0
        public static MutableString /*!*/ Read(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer)
        {
            self.AssertOpenedForReading();
            if (self.IsEndOfStream())
            {
                return(null);
            }

            if (buffer == null)
            {
                buffer = MutableString.CreateBinary();
            }

            buffer.Clear();
            if (!self.PreserveEndOfLines)
            {
                for (int i = 0; i < bytes; ++i)
                {
                    int c = self.ReadByteNormalizeEoln();
                    if (c == -1)
                    {
                        return(buffer);
                    }
                    else
                    {
                        buffer.Append((byte)c);
                    }
                }
            }
            else
            {
                var fixedBuffer = new byte[bytes];
                bytes = self.ReadBytes(fixedBuffer, 0, bytes);
                buffer.Append(fixedBuffer, 0, bytes);
            }

            return(buffer);
        }
Ejemplo n.º 6
0
        public static object Each(BlockParam block, RubyIO /*!*/ self, [DefaultProtocol] MutableString separator)
        {
            self.AssertOpenedForReading();

            MutableString line;

            while ((line = self.ReadLineOrParagraph(separator)) != null)
            {
                if (block == null)
                {
                    throw RubyExceptions.NoBlockGiven();
                }

                KernelOps.Taint(block.RubyContext, line);

                object result;
                if (block.Yield(line, out result))
                {
                    return(result);
                }
            }

            return(self);
        }
Ejemplo n.º 7
0
        public static object EachByte(BlockParam block, RubyIO/*!*/ self) {
            self.AssertOpenedForReading();
            object aByte;
            while ((aByte = Getc(self)) != null) {
                if (block == null) {
                    throw RubyExceptions.NoBlockGiven();
                }

                object result;
                if (block.Yield((int)aByte, out result)) {
                    return result;
                }
            }
            return self;
        }
Ejemplo n.º 8
0
        public static object Each(BlockParam block, RubyIO/*!*/ self, [DefaultProtocol]MutableString separator) {
            self.AssertOpenedForReading();

            MutableString line;
            while ((line = self.ReadLineOrParagraph(separator)) != null) {
                if (block == null) {
                    throw RubyExceptions.NoBlockGiven();
                }

                KernelOps.Taint(block.RubyContext, line);

                object result;
                if (block.Yield(line, out result)) {
                    return result;
                }
            }

            return self;
        }
Ejemplo n.º 9
0
 public static object Getc(RubyIO/*!*/ self) {
     self.AssertOpenedForReading();
     int c = self.ReadByteNormalizeEoln();
     return (c != -1) ? ScriptingRuntimeHelpers.Int32ToObject(c) : null;
 }
Ejemplo n.º 10
0
        public static int ReadChar(RubyIO/*!*/ self) {
            self.AssertOpenedForReading();
            int c = self.ReadByteNormalizeEoln();
            
            if (c == -1) {
                throw new EOFError("end of file reached");
            }

            return c;
        }
Ejemplo n.º 11
0
        public static MutableString/*!*/ Read(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
            self.AssertOpenedForReading();
            if (self.IsEndOfStream()) {
                return null;
            }

            if (buffer == null) {
                buffer = MutableString.CreateBinary();
            }

            buffer.Clear();
            if (!self.PreserveEndOfLines) {
                for (int i = 0; i < bytes; ++i) {
                    int c = self.ReadByteNormalizeEoln();
                    if (c == -1) {
                        return buffer;
                    } else {
                        buffer.Append((byte)c);
                    }
                }
            } else {
                var fixedBuffer = new byte[bytes];
                bytes = self.ReadBytes(fixedBuffer, 0, bytes);
                buffer.Append(fixedBuffer, 0, bytes);
            }

            return buffer;
        }
Ejemplo n.º 12
0
        public static MutableString/*!*/ Read(RubyIO/*!*/ self) {
            self.AssertOpenedForReading();

            if (!self.PreserveEndOfLines) {
                MutableString result = MutableString.CreateBinary();
                int c;
                while ((c = self.ReadByteNormalizeEoln()) != -1) {
                    result.Append((byte)c);
                }
                return result;
            } else {
                // TODO: change this once Binary mutable string uses resizable byte[] instead of List<byte>
                return MutableString.CreateBinary(ReadAllBytes(self));
            }
        }
Ejemplo n.º 13
0
 public static bool Eof(RubyIO/*!*/ self) {
     self.AssertOpenedForReading();
     return self.IsEndOfStream();
 }
Ejemplo n.º 14
0
        public static MutableString Read(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
            self.AssertOpenedForReading();
            if (bytes < 0) {
                throw RubyExceptions.CreateArgumentError("negative length -1 given");
            }

            if (buffer == null) {
                buffer = MutableString.CreateBinary();
            } else {
                buffer.Clear();
            }

            int bytesRead = self.AppendBytes(buffer, bytes);
            return (bytesRead == 0 && bytes != 0) ? null : buffer;
        }
Ejemplo n.º 15
0
 public static bool Eof(RubyIO /*!*/ self)
 {
     self.AssertOpenedForReading();
     return(self.IsEndOfStream());
 }