本文整理汇总了C#中IronRuby.StandardLibrary.StringIO.StringIO类的典型用法代码示例。如果您正苦于以下问题:C# StringIO类的具体用法?C# StringIO怎么用?C# StringIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringIO类属于IronRuby.StandardLibrary.StringIO命名空间,在下文中一共展示了StringIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenIO
public static object OpenIO([NotNull]BlockParam/*!*/ block, RubyClass/*!*/ self, [Optional]MutableString initialString, [Optional]MutableString mode) {
MutableStringStream stream = new MutableStringStream(initialString ?? MutableString.CreateBinary());
string ioMode = (mode != null) ? mode.ConvertToString() : "rb+";
RubyIO io = new StringIO(self.Context, stream, ioMode);
object result;
block.Yield(io, out result);
if (!io.Closed) {
io.Close();
}
return result;
}
示例2: Write
public static int Write(StringIO/*!*/ self, [NotNull]MutableString/*!*/ value) {
var content = self.GetWritableContent();
int length = content.GetByteCount();
var bytesWritten = value.GetByteCount();
int pos;
if ((self._mode & IOMode.WriteAppends) != 0) {
pos = length;
} else {
pos = self._position;
}
try {
content.WriteBytes(pos, value, 0, bytesWritten);
} catch (InvalidOperationException) {
throw RubyExceptions.CreateIOError("not modifiable string");
}
content.TaintBy(value);
self._position = pos + bytesWritten;
return bytesWritten;
}
示例3: IsConsole
public static bool IsConsole(StringIO/*!*/ self) {
// nop
return false;
}
示例4: Sync
public static bool Sync(StringIO/*!*/ self) {
// nop
return true;
}
示例5: GetDescriptor
public static object GetDescriptor(StringIO/*!*/ self) {
// nop
return null;
}
示例6: SetBinaryMode
public static StringIO/*!*/ SetBinaryMode(StringIO/*!*/ self) {
// nop
return self;
}
示例7: EachLine
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;
}
示例8: ReadLines
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: GetByte
public static object GetByte(StringIO/*!*/ self) {
var content = self.GetReadableContent();
if (self._position >= content.GetByteCount()) {
return null;
}
return ScriptingRuntimeHelpers.Int32ToObject(content.GetByte(self._position++));
}
示例10: SystemRead
public static MutableString/*!*/ SystemRead(StringIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional, NotNull]MutableString buffer) {
var result = Read(self, bytes, buffer);
if (result == null) {
throw new EOFError("end of file reached");
}
return result;
}
示例11: Read
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;
}
示例12: ReadLine
public static MutableString/*!*/ ReadLine(RubyScope/*!*/ scope, StringIO/*!*/ self, [DefaultProtocol]MutableString separator) {
// no dynamic call, modifies $_ scope variable:
MutableString result = Gets(scope, self, separator);
if (result == null) {
throw new EOFError("end of file reached");
}
return result;
}
示例13: SetPreviousByte
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");
}
}
}
示例14: ReadChar
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++);
}
示例15: EachByte
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;
}