Example #1
0
 internal static RubyRegexOptions MakeOptions(int options, MutableString encoding)
 {
     return((RubyRegexOptions)options | StringToRegexEncoding(encoding));
 }
Example #2
0
 public RubyFile(RubyContext /*!*/ context, MutableString /*!*/ path, IOMode mode)
     : this(context, context.DecodePath(path), mode)
 {
 }
Example #3
0
 public static IOMode Parse(MutableString mode, IOMode defaultMode)
 {
     return((mode != null) ? IOModeEnum.Parse(mode.ToString()) : defaultMode);
 }
Example #4
0
        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);
            }
        }
Example #5
0
 public RubyDir(RubyClass /*!*/ cls, MutableString /*!*/ dirname)
     : base(cls)
 {
     Reinitialize(this, dirname);
 }
Example #6
0
 public static MutableString /*!*/ GetName(TypeGroup /*!*/ self)
 {
     return(MutableString.CreateMutable().Append("TypeGroup of ").Append(self.Name));
 }
Example #7
0
        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));
        }
Example #8
0
 public static RubyRegex /*!*/ Create(RubyClass /*!*/ self,
                                      [DefaultProtocol, NotNull] MutableString /*!*/ pattern, int options, [DefaultProtocol, Optional] MutableString encoding)
 {
     return(new RubyRegex(pattern, MakeOptions(options, encoding)));
 }
Example #9
0
 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)));
 }
Example #10
0
        public static bool CaseCompare(RubyScope /*!*/ scope, RubyRegex /*!*/ self, [NotNull] MutableString /*!*/ str)
        {
            MatchData match = Match(scope, self, str);

            return((match != null && match.Success) ? true : false);
        }
Example #11
0
 public static MutableString /*!*/ Escape(RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ str)
 {
     return(RubyRegex.Escape(str).TaintBy(str));
 }
Example #12
0
        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);
        }
Example #13
0
 public static MatchData Match(RubyScope /*!*/ scope, RubyRegex /*!*/ self, [DefaultProtocol] MutableString str)
 {
     return(RubyRegex.SetCurrentMatchData(scope, self, str));
 }
Example #14
0
        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);
        }
Example #15
0
        /// <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);
        }
Example #16
0
 public static RubyRegex /*!*/ Reinitialize(RubyRegex /*!*/ self,
                                            [DefaultProtocol, NotNull] MutableString /*!*/ pattern, int options, [DefaultProtocol, Optional] MutableString encoding)
 {
     self.Set(pattern, MakeOptions(options, encoding));
     return(self);
 }
Example #17
0
 public static MutableString /*!*/ ToStr(string /*!*/ self)
 {
     return(MutableString.Create(self));
 }
Example #18
0
 internal BinaryContent(byte[] /*!*/ data, MutableString owner)
     : this(data, data.Length, owner)
 {
 }
Example #19
0
 public static MutableString /*!*/ ToS(object /*!*/ self)
 {
     return(MutableString.Create("main"));
 }
Example #20
0
 protected virtual BinaryContent /*!*/ Create(byte[] /*!*/ data, MutableString owner)
 {
     return(new BinaryContent(data, owner));
 }
Example #21
0
        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);
        }
Example #22
0
 public static object SetElement(RubyContext /*!*/ context, Thread /*!*/ self, [NotNull] MutableString /*!*/ key, object value)
 {
     return(SetElement(self, context.CreateSymbol(key), value));
 }
Example #23
0
 private void Close()
 {
     _dirName    = null;
     _rawEntries = null;
 }
Example #24
0
 public static object HasKey(RubyContext /*!*/ context, Thread /*!*/ self, [NotNull] MutableString /*!*/ key)
 {
     return(HasKey(self, context.CreateSymbol(key)));
 }
Example #25
0
 public static RubyDir /*!*/ Create(RubyClass /*!*/ self, [NotNull] MutableString /*!*/ dirname)
 {
     return(new RubyDir(self, dirname));
 }
Example #26
0
 public static RubyArray /*!*/ SetBacktrace(Exception /*!*/ self, [NotNull] MutableString /*!*/ backtrace)
 {
     return(RubyExceptionData.GetInstance(self).Backtrace = RubyArray.Create(backtrace));
 }
Example #27
0
 public static IOMode Parse(MutableString mode)
 {
     return(Parse(mode, IOMode.Default));
 }
Example #28
0
 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));
 }
Example #29
0
 internal CharArrayContent(char[] /*!*/ data, MutableString owner)
     : this(data, data.Length, owner)
 {
 }
Example #30
0
 internal static RubyRegexOptions MakeOptions(object ignoreCase, MutableString encoding)
 {
     return(ObjectToIgnoreCaseOption(ignoreCase) | StringToRegexEncoding(encoding));
 }