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))); } }
public MutableString ReadLineOrParagraph(MutableString separator, RubyEncoding /*!*/ encoding, bool preserveEndOfLines) { if (separator == null) { var result = MutableString.CreateBinary(); return(AppendBytes(result, Int32.MaxValue, preserveEndOfLines) == 0 ? null : result); } else if (separator.StartsWith('\n') && separator.GetLength() == 1) { return(ReadLine(encoding, preserveEndOfLines)); } else if (separator.IsEmpty) { return(ReadParagraph(encoding, preserveEndOfLines)); } else { return(ReadLine(separator, encoding, preserveEndOfLines)); } }
public void Set(MutableString /*!*/ pattern, RubyRegexOptions options) { ContractUtils.RequiresNotNull(pattern, "pattern"); // RubyRegexOptions.Once is only used to determine how the Regexp object should be created and cached. // It is not a property of the final object. /foo/ should compare equal with /foo/o. _options = options & ~RubyRegexOptions.Once; RubyEncoding encoding = RubyEncoding.GetRegexEncoding(options); if (encoding != null || pattern.Encoding.IsKCoding) { _pattern = MutableString.CreateBinary(pattern.ToByteArray(), encoding ?? RubyEncoding.Binary).Freeze(); } else { _pattern = pattern.PrepareForCharacterRead().Clone().Freeze(); } TransformPattern(encoding, options & RubyRegexOptions.EncodingMask); }
public static MutableString Read(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer) { self.RequireReadable(); 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); }
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); }
public MutableString ReadLine(MutableString /*!*/ separator, RubyEncoding /*!*/ encoding, bool preserveEndOfLines, int limit) { // TODO: limit int b = ReadByteNormalizeEoln(preserveEndOfLines); if (b == -1) { return(null); } int separatorOffset = 0; int separatorLength = separator.GetByteCount(); MutableString result = MutableString.CreateBinary(encoding); do { result.Append((byte)b); if (b == separator.GetByte(separatorOffset)) { if (separatorOffset == separatorLength - 1) { break; } separatorOffset++; } else if (separatorOffset > 0) { separatorOffset = 0; } b = ReadByteNormalizeEoln(preserveEndOfLines); } while (b != -1); return(result); }
public override MutableString /*!*/ GetPattern() { return(MutableString.CreateBinary(_pattern)); }
public MutableStringStream() : this(MutableString.CreateBinary()) { }