コード例 #1
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
        public static MutableString /*!*/ Read(StringIO /*!*/ self, MutableString buffer, bool eofError)
        {
            var content = self.GetReadableContent();
            int start   = self._position;
            int length  = content.GetByteCount();

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

            if (start < length)
            {
                self._position = length;
                buffer.Append(content, start, length - start).TaintBy(content);
            }
            else if (eofError)
            {
                throw new EOFError("end of file reached");
            }

            return(buffer);
        }
コード例 #2
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
        public static void SetPreviousByte(StringIO /*!*/ self, [DefaultProtocol] int b)
        {
            // MRI: this checks if the IO is readable although it actually modifies the string:
            MutableString content = self.GetReadableContent();

            int pos = self._position - 1;

            if (pos >= 0)
            {
                int length = content.GetByteCount();
                try {
                    if (pos >= length)
                    {
                        content.Append(0, pos - length);
                        content.Append(unchecked ((byte)b));
                    }
                    else
                    {
                        content.SetByte(pos, unchecked ((byte)b));
                    }
                    self._position = pos;
                } catch (InvalidOperationException) {
                    throw RubyExceptions.CreateIOError("not modifiable string");
                }
            }
        }
コード例 #3
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
        public static MutableString Read(StringIO /*!*/ self, [DefaultProtocol] int count, [DefaultProtocol, Optional, NotNull] MutableString buffer)
        {
            var content = self.GetReadableContent();

            if (count < 0)
            {
                throw RubyExceptions.CreateArgumentError("negative length -1 given");
            }

            if (buffer != null)
            {
                buffer.Clear();
            }

            int length = content.GetByteCount();

            if (self._position >= length)
            {
                return(null);
            }

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

            int bytesRead = Math.Min(count, length - self._position);

            buffer.Append(content, self._position, bytesRead).TaintBy(content);
            self._position += bytesRead;
            return(buffer);
        }
コード例 #4
0
        public static object EachLine(BlockParam block, StringIO /*!*/ self, [DefaultProtocol] MutableString separator)
        {
            // TODO: improve MSOps.EachLine
            var content = self.GetReadableContent();
            var result  = MutableStringOps.EachLine(block, content, separator, self._position);

            return(ReferenceEquals(result, content) ? self : result);
        }
コード例 #5
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
        public static object GetByte(StringIO /*!*/ self)
        {
            var content = self.GetReadableContent();

            if (self._position >= content.GetByteCount())
            {
                return(null);
            }

            return(ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(self._position++)));
        }
コード例 #6
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
        public static int ReadChar(StringIO /*!*/ self)
        {
            var content = self.GetReadableContent();
            int length  = content.GetByteCount();

            if (self._position >= length)
            {
                throw new EOFError("end of file reached");
            }

            return(content.GetByte(self._position++));
        }
コード例 #7
0
        public static MutableString Gets(RubyScope /*!*/ scope, StringIO /*!*/ self, [DefaultProtocol] MutableString separator)
        {
            var content = self.GetReadableContent();

            int           position = self._position;
            MutableString result   = ReadLine(content, separator, ref position);

            self._position = position;

            scope.GetInnerMostClosureScope().LastInputLine = result;
            self._lineNumber++;

            return(result);
        }
コード例 #8
0
        public static RubyArray /*!*/ ReadLines(StringIO /*!*/ self, [DefaultProtocol] MutableString separator)
        {
            var       content = self.GetReadableContent();
            RubyArray result  = new RubyArray();

            // no dynamic call, doesn't modify $_ scope variable:
            MutableString line;
            int           position = self._position;

            while ((line = ReadLine(content, separator, ref position)) != null)
            {
                result.Add(line);
                self._lineNumber++;
            }
            self._position = position;
            return(result);
        }
コード例 #9
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
        public static object EachByte(BlockParam block, StringIO /*!*/ self)
        {
            MutableString content;
            int           pos;

            while ((pos = self._position) < (content = self.GetReadableContent()).GetByteCount())
            {
                if (block == null)
                {
                    throw RubyExceptions.NoBlockGiven();
                }

                self._position++;

                object result;
                if (block.Yield(ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(pos)), out result))
                {
                    return(result);
                }
            }
            return(null);
        }
コード例 #10
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
 public static void CloseRead(StringIO/*!*/ self) {
     self.GetReadableContent();
     self._mode = self._mode.CloseRead();
 }
コード例 #11
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static RubyArray/*!*/ ReadLines(StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
            var content = self.GetReadableContent();
            RubyArray result = new RubyArray();

            // no dynamic call, doesn't modify $_ scope variable:
            MutableString line;
            int position = self._position;
            while ((line = ReadLine(content, separator, ref position)) != null) {
                result.Add(line);
                self._lineNumber++;
            }
            self._position = position;
            return result;
        }
コード例 #12
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static MutableString/*!*/ Read(StringIO/*!*/ self, MutableString buffer, bool eofError) {
            var content = self.GetReadableContent();
            int start = self._position;
            int length = content.GetByteCount();

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

            if (start < length) {
                self._position = length;
                buffer.Append(content, start, length - start).TaintBy(content);
            } else if (eofError) {
                throw new EOFError("end of file reached");
            }

            return buffer;
        }
コード例 #13
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
 public static bool Eof(StringIO/*!*/ self) {
     var context = self.GetReadableContent();
     return self._position >= context.GetByteCount();
 }
コード例 #14
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static object GetByte(StringIO/*!*/ self) {
            var content = self.GetReadableContent();

            if (self._position >= content.GetByteCount()) {
                return null;
            }

            return ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(self._position++));
        }
コード例 #15
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static MutableString Read(StringIO/*!*/ self, [DefaultProtocol]int count, [DefaultProtocol, Optional, NotNull]MutableString buffer) {
            var content = self.GetReadableContent();
            if (count < 0) {
                throw RubyExceptions.CreateArgumentError("negative length -1 given");
            }

            if (buffer != null) {
                buffer.Clear();
            }

            int length = content.GetByteCount();
            if (self._position >= length) {
                return null;
            }

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

            int bytesRead = Math.Min(count, length - self._position);
            buffer.Append(content, self._position, bytesRead).TaintBy(content);
            self._position += bytesRead;
            return buffer;
        }
コード例 #16
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
 public static void CloseRead(StringIO /*!*/ self)
 {
     self.GetReadableContent();
     self._mode = self._mode.CloseRead();
 }
コード例 #17
0
ファイル: StringIO.cs プロジェクト: parhelia512/ironruby
        public static bool Eof(StringIO /*!*/ self)
        {
            var context = self.GetReadableContent();

            return(self._position >= context.GetByteCount());
        }
コード例 #18
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static object EachByte(BlockParam block, StringIO/*!*/ self) {
            MutableString content;
            int pos;
            while ((pos = self._position) < (content = self.GetReadableContent()).GetByteCount()) {
                if (block == null) {
                    throw RubyExceptions.NoBlockGiven();
                }

                self._position++;

                object result;
                if (block.Yield(ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(pos)), out result)) {
                    return result;
                }
            }
            return null;
        }
コード例 #19
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
 public static object EachLine(BlockParam block, StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
     // TODO: improve MSOps.EachLine
     var content = self.GetReadableContent();
     var result = MutableStringOps.EachLine(block, content, separator, self._position);
     return ReferenceEquals(result, content) ? self : result;
 }
コード例 #20
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static void SetPreviousByte(StringIO/*!*/ self, [DefaultProtocol]int b) {
            // MRI: this checks if the IO is readable although it actually modifies the string:
            MutableString content = self.GetReadableContent();

            int pos = self._position - 1;
            if (pos >= 0) {
                int length = content.GetByteCount();
                try {
                    if (pos >= length) {
                        content.Append(0, pos - length);
                        content.Append(unchecked((byte)b));
                    } else {
                        content.SetByte(pos, unchecked((byte)b));
                    }
                    self._position = pos;
                } catch (InvalidOperationException) {
                    throw RubyExceptions.CreateIOError("not modifiable string");
                }
            }
        }
コード例 #21
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static MutableString Gets(RubyScope/*!*/ scope, StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
            var content = self.GetReadableContent();

            int position = self._position;
            MutableString result = ReadLine(content, separator, ref position);
            self._position = position;

            scope.GetInnerMostClosureScope().LastInputLine = result;
            self._lineNumber++;

            return result;
        }
コード例 #22
0
ファイル: StringIO.cs プロジェクト: jxnmaomao/ironruby
        public static int ReadChar(StringIO/*!*/ self) {
            var content = self.GetReadableContent();
            int length = content.GetByteCount();

            if (self._position >= length) {
                throw new EOFError("end of file reached");
            }

            return content.GetByte(self._position++);
        }