internal static RubyRegexOptions MakeOptions(int options, MutableString encoding) { return((RubyRegexOptions)options | StringToRegexEncoding(encoding)); }
public RubyFile(RubyContext /*!*/ context, MutableString /*!*/ path, IOMode mode) : this(context, context.DecodePath(path), mode) { }
public static IOMode Parse(MutableString mode, IOMode defaultMode) { return((mode != null) ? IOModeEnum.Parse(mode.ToString()) : defaultMode); }
private static object ChangeDirectory(PlatformAdaptationLayer /*!*/ pal, string /*!*/ strDir, MutableString /*!*/ dir, BlockParam block) { if (block == null) { SetCurrentDirectory(pal, strDir); return(0); } string current = pal.CurrentDirectory; try { SetCurrentDirectory(pal, strDir); object result; block.Yield(dir, out result); return(result); } finally { SetCurrentDirectory(pal, current); } }
public RubyDir(RubyClass /*!*/ cls, MutableString /*!*/ dirname) : base(cls) { Reinitialize(this, dirname); }
public static MutableString /*!*/ GetName(TypeGroup /*!*/ self) { return(MutableString.CreateMutable().Append("TypeGroup of ").Append(self.Name)); }
public static object Evaluate(RubyScope /*!*/ scope, BlockParam block, RubyModule /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ code, [Optional, NotNull] MutableString file, [DefaultParameterValue(1)] int line) { if (block != null) { throw RubyExceptions.CreateArgumentError("wrong number of arguments"); } return(RubyUtils.Evaluate(code, scope, self, self, file, line)); }
public static RubyRegex /*!*/ Create(RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ pattern, int options, [DefaultProtocol, Optional] MutableString encoding) { return(new RubyRegex(pattern, MakeOptions(options, encoding))); }
public static RubyRegex /*!*/ Create(RubyScope /*!*/ scope, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ pattern, [DefaultParameterValue(null)] object ignoreCase, [DefaultProtocol, Optional] MutableString encoding) { return(new RubyRegex(pattern, MakeOptions(ignoreCase, encoding))); }
public static bool CaseCompare(RubyScope /*!*/ scope, RubyRegex /*!*/ self, [NotNull] MutableString /*!*/ str) { MatchData match = Match(scope, self, str); return((match != null && match.Success) ? true : false); }
public static MutableString /*!*/ Escape(RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ str) { return(RubyRegex.Escape(str).TaintBy(str)); }
public static object MatchIndex(RubyScope /*!*/ scope, RubyRegex /*!*/ self, [DefaultProtocol] MutableString /*!*/ str) { MatchData match = RubyRegex.SetCurrentMatchData(scope, self, str); return((match != null) ? ScriptingRuntimeHelpers.Int32ToObject(match.Index) : null); }
public static MatchData Match(RubyScope /*!*/ scope, RubyRegex /*!*/ self, [DefaultProtocol] MutableString str) { return(RubyRegex.SetCurrentMatchData(scope, self, str)); }
internal static MutableString /*!*/ AppendEscapeForwardSlash(MutableString /*!*/ result, MutableString /*!*/ pattern) { int first = 0; int i = SkipToUnescapedForwardSlash(pattern, 0); while (i >= 0) { Debug.Assert(i < pattern.Length); Debug.Assert(pattern.GetChar(i) == '/' && (i == 0 || pattern.GetChar(i - 1) != '\\')); result.Append(pattern, first, i - first); result.Append('\\'); first = i; // include forward slash in the next append i = SkipToUnescapedForwardSlash(pattern, i + 1); } result.Append(pattern, first, pattern.Length - first); return(result); }
/// <summary> /// Reads <paramref name="count"/> bytes from the stream and appends them to the given <paramref name="buffer"/>. /// If <paramref name="count"/> is <c>Int32.MaxValue</c> the stream is read to the end. /// Unless <paramref name="preserveEndOfLines"/> is set the line endings in the appended data are normalized to "\n". /// </summary> public int AppendBytes(MutableString /*!*/ buffer, int count, bool preserveEndOfLines) { ContractUtils.RequiresNotNull(buffer, "buffer"); ContractUtils.Requires(count >= 0, "count"); if (count == 0) { return(0); } bool readAll = count == Int32.MaxValue; buffer.SwitchToBytes(); int initialBufferSize = buffer.GetByteCount(); if (preserveEndOfLines) { AppendRawBytes(buffer, count); } else { // allocate 3 more bytes at the end for a backstop and possible LF: byte[] bytes = Utils.EmptyBytes; int done = initialBufferSize; bool eof; do { AppendRawBytes(buffer, readAll ? 1024 : count); int end = buffer.GetByteCount(); int bytesRead = end - done; if (bytesRead == 0) { break; } eof = bytesRead < count; buffer.EnsureCapacity(end + 3); int byteCount; bytes = buffer.GetByteArray(out byteCount); if (bytes[end - 1] == CR && PeekByte(0) == LF) { ReadByte(); bytes[end++] = LF; } // insert backstop: bytes[end] = CR; bytes[end + 1] = LF; int last = IndexOfCrLf(bytes, done); count -= last - done; done = last; while (last < end) { int next = IndexOfCrLf(bytes, last + 2); int chunk = next - last - 1; Buffer.BlockCopy(bytes, last + 1, bytes, done, chunk); done += chunk; count -= chunk; last = next; } buffer.Remove(done); } while (readAll || count > 0 && !eof); } if (readAll) { buffer.TrimExcess(); } return(buffer.GetByteCount() - initialBufferSize); }
public static RubyRegex /*!*/ Reinitialize(RubyRegex /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ pattern, int options, [DefaultProtocol, Optional] MutableString encoding) { self.Set(pattern, MakeOptions(options, encoding)); return(self); }
public static MutableString /*!*/ ToStr(string /*!*/ self) { return(MutableString.Create(self)); }
internal BinaryContent(byte[] /*!*/ data, MutableString owner) : this(data, data.Length, owner) { }
public static MutableString /*!*/ ToS(object /*!*/ self) { return(MutableString.Create("main")); }
protected virtual BinaryContent /*!*/ Create(byte[] /*!*/ data, MutableString owner) { return(new BinaryContent(data, owner)); }
public static void SetAutoloadedConstant(RubyModule /*!*/ self, [DefaultProtocol, NotNull] string /*!*/ constantName, [DefaultProtocol, NotNull] MutableString /*!*/ path) { self.Context.CheckConstantName(constantName); if (path.IsEmpty) { throw RubyExceptions.CreateArgumentError("empty file name"); } self.SetAutoloadedConstant(constantName, path); }
public static object SetElement(RubyContext /*!*/ context, Thread /*!*/ self, [NotNull] MutableString /*!*/ key, object value) { return(SetElement(self, context.CreateSymbol(key), value)); }
private void Close() { _dirName = null; _rawEntries = null; }
public static object HasKey(RubyContext /*!*/ context, Thread /*!*/ self, [NotNull] MutableString /*!*/ key) { return(HasKey(self, context.CreateSymbol(key))); }
public static RubyDir /*!*/ Create(RubyClass /*!*/ self, [NotNull] MutableString /*!*/ dirname) { return(new RubyDir(self, dirname)); }
public static RubyArray /*!*/ SetBacktrace(Exception /*!*/ self, [NotNull] MutableString /*!*/ backtrace) { return(RubyExceptionData.GetInstance(self).Backtrace = RubyArray.Create(backtrace)); }
public static IOMode Parse(MutableString mode) { return(Parse(mode, IOMode.Default)); }
public int WriteBytes(MutableString /*!*/ buffer, int offset, int count, bool preserveEndOfLines) { // TODO: this is not safe, we are passing an internal pointer to the byte[] content of MutableString to the Stream: return(WriteBytes(buffer.SwitchToBytes().GetByteArrayChecked(offset, count), offset, count, preserveEndOfLines)); }
internal CharArrayContent(char[] /*!*/ data, MutableString owner) : this(data, data.Length, owner) { }
internal static RubyRegexOptions MakeOptions(object ignoreCase, MutableString encoding) { return(ObjectToIgnoreCaseOption(ignoreCase) | StringToRegexEncoding(encoding)); }