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); }
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"); } } }
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); }
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); }
public static object GetByte(StringIO /*!*/ self) { var content = self.GetReadableContent(); if (self._position >= content.GetByteCount()) { return(null); } return(ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(self._position++))); }
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++)); }
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); }
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); }
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); }
public static void CloseRead(StringIO/*!*/ self) { self.GetReadableContent(); self._mode = self._mode.CloseRead(); }
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; }
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; }
public static bool Eof(StringIO/*!*/ self) { var context = self.GetReadableContent(); return self._position >= context.GetByteCount(); }
public static object GetByte(StringIO/*!*/ self) { var content = self.GetReadableContent(); if (self._position >= content.GetByteCount()) { return null; } return ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(self._position++)); }
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; }
public static void CloseRead(StringIO /*!*/ self) { self.GetReadableContent(); self._mode = self._mode.CloseRead(); }
public static bool Eof(StringIO /*!*/ self) { var context = self.GetReadableContent(); return(self._position >= context.GetByteCount()); }
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; }
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; }
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"); } } }
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; }
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++); }