Ejemplo n.º 1
1
 public static object Load(RubyScope/*!*/ scope, RubyModule/*!*/ self, MutableString/*!*/ libraryName)
 {
     object loaded;
     scope.RubyContext.Loader.LoadFile(null, self, libraryName, LoadFlags.ResolveLoaded | LoadFlags.AnyLanguage, out loaded);
     Debug.Assert(loaded != null);
     return loaded;
 }
Ejemplo n.º 2
0
        public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path, int mode) {
            if (path.IsEmpty) {
                throw new Errno.InvalidError();
            }

            return new RubyFile(self.Context, path.ConvertToString(), (RubyFileMode)mode);
        }
Ejemplo n.º 3
0
 /*!*/
 public static IEnumerable<MutableString> GetMatches(RubyContext/*!*/ context, MutableString/*!*/ pattern, int flags)
 {
     string strPattern = context.DecodePath(pattern);
     foreach (string strFileName in GetMatches(context.Platform, strPattern, flags)) {
         yield return context.EncodePath(strFileName).TaintBy(pattern);
     }
 }
Ejemplo n.º 4
0
 static RubyFileOps()
 {
     ALT_SEPARATOR = MutableString.CreateAscii(AltDirectorySeparatorChar.ToString()).Freeze();
     SEPARATOR = MutableString.CreateAscii(DirectorySeparatorChar.ToString()).Freeze();
     Separator = SEPARATOR;
     PATH_SEPARATOR = MutableString.CreateAscii(PathSeparatorChar.ToString()).Freeze();
 }
Ejemplo n.º 5
0
Archivo: Ruby.cs Proyecto: revam/Gemini
 /// <summary>
 /// Inflates the compressed string using Ruby's Zlib module
 /// </summary>
 /// <param name="data">The Ruby string to decompress</param>
 /// <returns>The decompressed Ruby string as a System.String</returns>
 public static string ZlibInflate(MutableString data)
 {
     _rubyScope.SetVariable("data", data);
       MutableString result = _rubyEngine.Execute(@"Zlib::Inflate.inflate(data)", _rubyScope);
       _rubyScope.RemoveVariable("data");
       return ConvertString(result);
 }
Ejemplo n.º 6
0
 public Subclass(RubyClass/*!*/ rubyClass, MutableString begin, MutableString end, bool excludeEnd)
     : base(begin, end, excludeEnd)
 {
     Assert.NotNull(rubyClass);
     Debug.Assert(!rubyClass.IsSingletonClass);
     ImmediateClass = rubyClass;
 }
Ejemplo n.º 7
0
 public Range(MutableString/*!*/ begin, MutableString/*!*/ end, bool excludeEnd)
 {
     _begin = begin;
     _end = end;
     _excludeEnd = excludeEnd;
     _initialized = true;
 }
Ejemplo n.º 8
0
 private JsonWriter()
 {
     Nesting = new Stack<JsonWriterState>();
     Nesting.Push(new JsonWriterState(JsonNodeType.None));
     Indent = new MutableString();
     Settings = Settings ?? JsonWriterSettings.Terse;
 }
 internal CharArrayContent(char[]/*!*/ data, int count, MutableString owner) 
     : base(owner) {
     Assert.NotNull(data);
     Debug.Assert(count >= 0 && count <= data.Length);
     _data = data;
     _count = count;
 }
Ejemplo n.º 10
0
        public void ICloneable_op_Clone()
        {
            ICloneable expected = new MutableString("One");
            var actual = expected.Clone();

            Assert.Equal(expected, actual);
            Assert.NotSame(expected, actual);
        }
Ejemplo n.º 11
0
 public static MutableString FastXs(RubyContext/*!*/ context, MutableString/*!*/ self)
 {
     //TODO: we are assuming that every string is UTF8, but this is wrong
     String utf8String = Encoding.UTF8.GetString(self.ToByteArray());
     StringBuilder builder = new StringBuilder((int)(utf8String.Length * 1.5));
     Entities.XML.Escape(builder, utf8String);
     return MutableString.CreateAscii(builder.ToString());
 }
Ejemplo n.º 12
0
 private void InitializeFrom(StringScanner/*!*/ other) {
     _currentPosition = other._currentPosition;
     _foundPosition = other._foundPosition;
     _lastMatch = other._lastMatch;
     _lastMatchingGroups = other._lastMatchingGroups;
     _previousPosition = other._previousPosition;
     _scanString = other.ScanString;
 }
Ejemplo n.º 13
0
        public void IComparableOfMutableString_op_CompareTo_objectNull()
        {
            IComparable<MutableString> obj = new MutableString("a");

            var expected = string.CompareOrdinal("a", null);

            Assert.Equal(expected, obj.CompareTo(null));
        }
Ejemplo n.º 14
0
            public static RubyArray Execute(RhoDatabase/*!*/ self, MutableString/*!*/ sqlStatement, Boolean isBatch, RubyArray args)
            {
                try
                {
                    RubyArray retArr = new RubyArray();

                    if (isBatch)
                    {
                        self.m_db.executeBatchSQL(sqlStatement.ToString());
                    }
                    else
                    {
                        Object[] values = null;
                        if (args != null && args.Count > 0)
                        {
                            if (args[0] != null && args[0] is RubyArray)
                                values = ((RubyArray)args[0]).ToArray();
                            else
                                values = args.ToArray();
                        }

                        try
                        {
                            self.m_db.Lock();
                            using (IDBResult rows = self.m_db.executeSQL(sqlStatement.ToString(), values, true))
                            {
                                if (rows != null)
                                {
                                    MutableString[] colNames = null;
                                    for (; !rows.isEnd(); rows.next())
                                    {
                                        IDictionary<object, object> map = new Dictionary<object, object>();
                                        Hash row = new Hash(map);
                                        for (int nCol = 0; nCol < rows.getColCount(); nCol++)
                                        {
                                            if (colNames == null)
                                                colNames = getOrigColNames(rows);

                                            row.Add(colNames[nCol], rows.getRubyValueByIdx(nCol));
                                        }
                                        retArr.Add(row);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            self.m_db.Unlock();
                        }
                    }

                    return retArr;
                }catch (Exception exc)
                {
                    //TODO: throw ruby exception
                    throw exc;
                }
            }
Ejemplo n.º 15
0
 internal Node Scalar(MutableString taguri, MutableString value, SymbolId style) {
     return Scalar(
         taguri != null ? taguri.ConvertToString() : "",
         value != null ? value.ConvertToString() : "",
         //It's not clear what style argument really means, it seems to be always :plain
         //for now we are ignoring it, defaulting to \0 (see Representer class)
         '\0'
     );
 }
Ejemplo n.º 16
0
        public void IComparableOfMutableString_op_CompareTo_MutableString(string comparand1,
                                                                          string comparand2)
        {
            IComparable<MutableString> obj = new MutableString(comparand1);
            var expected = string.CompareOrdinal(comparand1, comparand2);
            var actual = obj.CompareTo(comparand2);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 17
0
 public static unsafe IntPtr GetBytePtr(MutableString str)
 {
     IntPtr pp;
       fixed (byte* bp = str.ToByteArray())
       {
     pp = (IntPtr)bp;
       }
       return pp;
 }
Ejemplo n.º 18
0
        public static string Decode(string value)
        {
            var result = new MutableString(WebUtility.HtmlDecode(value));
            foreach (var entity in _entities)
            {
                result.Replace(entity.Key, entity.Value);
            }

            return result;
        }
Ejemplo n.º 19
0
        private static MutableString/*!*/ CheckContent(MutableString/*!*/ content, IOMode mode) {
            if (content.IsFrozen && mode.CanWrite()) {
                throw Errno.CreateEACCES("Permission denied");
            }

            if ((mode & IOMode.Truncate) != 0) {
                content.Clear();
            }
            return content;
        }
Ejemplo n.º 20
0
        public static object/*!*/ Require(RubyScope/*!*/ scope, RubyModule/*!*/ self, MutableString/*!*/ libraryName) {
            object loaded;
            
            scope.RubyContext.Loader.LoadFile(
                null, self, libraryName, LoadFlags.LoadOnce | LoadFlags.AppendExtensions | LoadFlags.ResolveLoaded, out loaded
            );

            Debug.Assert(loaded != null);
            return loaded;
        }
Ejemplo n.º 21
0
 public RubyDir([NotNull]MutableString/*!*/ dirname) {
     string strName = dirname.ConvertToString();
     try {
         _rawEntries = Directory.GetFileSystemEntries(strName);
     } catch (Exception ex) {
         throw ToRubyException(ex, strName, DirectoryOperation.Open);
     }
     _dirName = MutableString.Create(RubyUtils.CanonicalizePath(strName), RubyEncoding.Path);
     _closed = false;
     _pos = -2;
 }
Ejemplo n.º 22
0
        private MatchData(Match/*!*/ match, MutableString/*!*/ originalString, int[] kIndices) {
            Debug.Assert(match.Success);
            
            _match = match;

            // TODO (opt): create groups instead?
            _originalString = originalString;

            _kIndices = kIndices;
            IsTainted = originalString.IsTainted;
        }
Ejemplo n.º 23
0
        internal void WriteMessage(MutableString/*!*/ message) {
            if (_WriteSite == null) {
                Interlocked.CompareExchange(
                    ref _WriteSite,
                    CallSite<Func<CallSite, object, object, object>>.Create(RubyCallAction.Make(_context, "write", 1)),
                    null
                );
            }

            _WriteSite.Target(_WriteSite, _context.StandardErrorOutput, message);
        }
Ejemplo n.º 24
0
        public static IOInfo Parse(RubyContext/*!*/ context, MutableString/*!*/ modeAndEncoding) {
            if (!modeAndEncoding.IsAscii()) {
                throw IOModeEnum.IllegalMode(modeAndEncoding.ToAsciiString(false));
            }

            string[] parts = modeAndEncoding.ToString().Split(':');
            return new IOInfo(
                IOModeEnum.Parse(parts[0]),
                (parts.Length > 1) ? TryParseEncoding(context, parts[1]) : null,
                (parts.Length > 2) ? TryParseEncoding(context, parts[2]) : null
            );
        }
Ejemplo n.º 25
0
        public static object BlockReplaceAll(ConversionStorage<MutableString>/*!*/ tosConversion, 
            RubyScope/*!*/ scope, [NotNull]BlockParam/*!*/ block, MutableString/*!*/ self, 
            [NotNull]RubyRegex pattern)
        {
            object blockResult;
            MutableString result;
            self.TrackChanges();
            object r = BlockReplaceAll(tosConversion, scope, self, block, pattern, out blockResult, out result) ? blockResult : (result ?? self.Clone());

            RequireNoVersionChange(self);
            return r;
        }
Ejemplo n.º 26
0
        private static int ReadUtf8CodePoint(MutableString/*!*/ data, ref int index) {
            int length = data.GetByteCount();
            if (index >= length) {
                return -1;
            }
            int b = data.GetByte(index++);
            int count, mask;
            if ((b & 0x80) == 0) {
                count = 1;
                mask = 0xff;
            } else if ((b & 0xe0) == 0xc0) {
                count = 2;
                mask = 0x1f;
            } else if ((b & 0xf0) == 0xe0) {
                count = 3;
                mask = 0x0f;
            } else if ((b & 0xf8) == 0xf0) {
                count = 4;
                mask = 0x07;
            } else if ((b & 0xfc) == 0xf8) {
                count = 5;
                mask = 0x03;
            } else if ((b & 0xfe) == 0xfc) {
                count = 6;
                mask = 0x01;
            } else {
                throw RubyExceptions.CreateArgumentError("malformed UTF-8 character");
            }

            int codepoint = b & mask;
            for (int i = 1; i < count; i++) {
                if (index >= length) {
                    throw RubyExceptions.CreateArgumentError(
                        "malformed UTF-8 character (expected {0} bytes, given {1} bytes)", count, i
                    );
                }
                b = data.GetByte(index++);
                if ((b & 0xc0) != 0x80) {
                    throw RubyExceptions.CreateArgumentError("malformed UTF-8 character");
                }

                codepoint = (codepoint << 6) | (b & 0x3f);
            }

            int requiredCount;
            int mark;
            GetCodePointByteCount(codepoint, out requiredCount, out mark);
            if (requiredCount != count) {
                throw RubyExceptions.CreateArgumentError("redundant UTF-8 sequence");
            }
            return codepoint;
        }
Ejemplo n.º 27
0
        public ParserEngineState(Parser parser, RubyScope scope, MutableString source)
        {
            Parser = parser;
            Scope = scope;
            OriginalSource = source;
            Source = source.ConvertToString();

            CreateID = Helpers.GetCreateId(scope);
            AllowNaN = DEFAULT_ALLOW_NAN;
            MaxNesting = DEFAULT_MAX_NESTING;
            CurrentNesting = 0;
            Memo = 0;
        }
Ejemplo n.º 28
0
 internal static Process/*!*/ CreateProcess(RubyContext/*!*/ context, MutableString/*!*/ command, MutableString[]/*!*/ args) {
     var psi = new ProcessStartInfo(command.ToString(), JoinArguments(args).ToString());
     psi.UseShellExecute = false;
     psi.RedirectStandardError = true;
     try {
         Utils.Log(String.Format("Starting: '{0}' with args: '{1}'", psi.FileName, psi.Arguments), "PROCESS");
         Process p = Process.Start(psi);
         p.WaitForExit();
         context.ChildProcessExitStatus = new RubyProcess.Status(p);
         return p;
     } catch (Exception e) {
         throw RubyExceptions.CreateENOENT(psi.FileName, e);
     }
 }
Ejemplo n.º 29
0
        public Parser(RubyScope scope, MutableString source, Hash options)
        {
            InitializeLibrary(scope);

            _json = new ParserEngineState(this, scope, source);
            if (options.Count > 0) {
                if (options.ContainsKey(_maxNesting)) {
                    _json.MaxNesting = options[_maxNesting] is int ? (int)options[_maxNesting] : 0;
                }
                _json.AllowNaN = options.ContainsKey(_allowNan) ? (bool)options[_allowNan] : ParserEngineState.DEFAULT_ALLOW_NAN;
                // TODO: check needed, create_id could be TrueClass, FalseClass, NilClass or String
                _json.CreateID = options.ContainsKey(_createAdditions) && (bool)options[_createAdditions] ? Helpers.GetCreateId(scope) : null;
            }
        }
Ejemplo n.º 30
0
        public IOInfo AddModeAndEncoding(RubyContext/*!*/ context, MutableString/*!*/ modeAndEncoding) {
            IOInfo info = Parse(context, modeAndEncoding);
            if (_mode.HasValue) {
                throw RubyExceptions.CreateArgumentError("mode specified twice");
            }

            if (!HasEncoding) {
                return info;
            }

            if (!info.HasEncoding) {
                return new IOInfo(info.Mode, _externalEncoding, _internalEncoding);
            }

            throw RubyExceptions.CreateArgumentError("encoding specified twice");
        }
Ejemplo n.º 31
0
 public void I2([NotNull] MutableString a)
 {
 }
Ejemplo n.º 32
0
        public void OverloadResolution_Numeric1()
        {
            var metaBuilder = new MetaObjectBuilder(null);

            Context.ObjectClass.SetConstant("X", Context.GetClass(typeof(Overloads1.X)));

            object c   = Engine.Execute(@"class C < X; new; end");
            var    sym = Context.CreateAsciiSymbol("x");
            var    ms  = MutableString.CreateAscii("x");

            var cases = new[] {
                // F
                new { Args = new[] { MO(1) }, Overloads = "F*", Result = "F1" },
                new { Args = new[] { MO((byte)1) }, Overloads = "F*", Result = "F1" },
                new { Args = new[] { MO(1L) }, Overloads = "F*", Result = "F2" },
                new { Args = new[] { MO(1.2F) }, Overloads = "F*", Result = "F3" },

                // G
                new { Args = new[] { MO(1) }, Overloads = "G*", Result = "G1" },
                new { Args = new[] { MO((byte)1) }, Overloads = "G*", Result = "G1" },
                new { Args = new[] { MO(1L) }, Overloads = "G*", Result = "G2" },
                new { Args = new[] { MO(1.2F) }, Overloads = "G*", Result = "G3" },
                new { Args = new[] { MO(c) }, Overloads = "G*", Result = "G1" },

                // I
                new { Args = new[] { MO(c) }, Overloads = "I*", Result = "I3" },

                // J
                new { Args = new[] { MO(1) }, Overloads = "J*", Result = "J1" },
                new { Args = new[] { MO((BigInteger)1000) }, Overloads = "J*", Result = "J2" },
                new { Args = new[] { MO((byte)12) }, Overloads = "J*", Result = "J1" },
                new { Args = new[] { MO(c) }, Overloads = "J*", Result = "J3" },
                new { Args = new[] { MO(1.0) }, Overloads = "J*", Result = "J3" },

                // K
                new { Args = new[] { MO(1) }, Overloads = "K*", Result = "K2" },
                new { Args = new[] { MO(c) }, Overloads = "K*", Result = "K1" },
                new { Args = new[] { MO("x") }, Overloads = "K*", Result = "K1" },

                // L
                new { Args = new[] { MO(sym), MO(sym) }, Overloads = "L*", Result = "L1" },
                new { Args = new[] { MO("x"), MO(sym) }, Overloads = "L*", Result = "L2" },
                new { Args = new[] { MO(ms), MO(sym) }, Overloads = "L*", Result = "L3" },
                new { Args = new[] { MO(null), MO(sym) }, Overloads = "L*", Result = "L3" },
                new { Args = new[] { MO(c), MO(sym) }, Overloads = "L*", Result = "L3" },

                // M
                new { Args = new[] { MO(1) }, Overloads = "M*", Result = "M1" },
                new { Args = new[] { MO(Overloads1.E.A) }, Overloads = "M*", Result = "M2" },

                // N
                new { Args = new[] { MO(MutableString.CreateAscii("x")) }, Overloads = "N*", Result = "N1" },
            };

            for (int i = 0; i < cases.Length; i++)
            {
                var args      = new CallArguments(Context, MO(new Overloads1()), cases[i].Args, RubyCallSignature.Simple(cases[i].Args.Length));
                var resolver  = new RubyOverloadResolver(metaBuilder, args, SelfCallConvention.SelfIsInstance, false);
                var overloads = GetInstanceMethods(typeof(Overloads1), cases[i].Overloads);
                var result    = resolver.ResolveOverload(i.ToString(), overloads, NarrowingLevel.None, NarrowingLevel.All);

                Assert(result.Success && result.Overload.Name == cases[i].Result);
            }
        }
Ejemplo n.º 33
0
 public static Exception /*!*/ Create(MutableString /*!*/ message)
 {
     return(RubyExceptionData.InitializeException(new SocketException(0), message));
 }
Ejemplo n.º 34
0
 public static TCPServer /*!*/ Reinitialize(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast,
                                            TCPServer /*!*/ self, [DefaultProtocol] MutableString hostname, [DefaultParameterValue(null)] object port)
 {
     self.Socket = CreateSocket(stringCast, fixnumCast, hostname, port);
     return(self);
 }
Ejemplo n.º 35
0
        private static Socket CreateSocket(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast,
                                           [DefaultProtocol] MutableString hostname, [DefaultParameterValue(null)] object port)
        {
            IPAddress listeningInterface = null;

            if (hostname == null)
            {
                listeningInterface = new IPAddress(0);
            }
            else if (hostname.IsEmpty)
            {
                listeningInterface = IPAddress.Any;
            }
            else
            {
                string hostnameStr = hostname.ConvertToString();
                if (hostnameStr == IPAddress.Any.ToString())
                {
                    listeningInterface = IPAddress.Any;
                }
                else if (hostnameStr == IPAddress.Loopback.ToString())
                {
                    listeningInterface = IPAddress.Loopback;
                }
                else if (!IPAddress.TryParse(hostnameStr, out listeningInterface))
                {
                    // look up the host IP from DNS
                    IPHostEntry hostEntry = Dns.GetHostEntry(hostnameStr);
                    foreach (IPAddress address in hostEntry.AddressList)
                    {
                        if (address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            listeningInterface = address;
                            break;
                        }
                    }
                    if (listeningInterface == null)
                    {
                        // TODO: do we need to support any other address family types?
                        // (presumably should support at least IPv6)
                        throw new NotImplementedException("TODO: non-inet addresses");
                    }
                }
                Assert.NotNull(listeningInterface);
            }

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try {
                socket.Bind(new IPEndPoint(listeningInterface, ConvertToPortNum(stringCast, fixnumCast, port)));
                socket.Listen(10);
            } catch (SocketException e) {
                switch (e.SocketErrorCode)
                {
                case SocketError.AddressAlreadyInUse:
                    throw new Errno.AddressInUseError();

                default:
                    throw;
                }
            }
            return(socket);
        }
Ejemplo n.º 36
0
        public bool LoadFile(Scope globalScope, object self, MutableString /*!*/ path, LoadFlags flags)
        {
            object loaded;

            return(LoadFile(globalScope, self, path, flags, out loaded));
        }
Ejemplo n.º 37
0
 private void AddLoadedFile(MutableString /*!*/ path)
 {
     lock (_loadedFiles) {
         _loadedFiles.Add(path);
     }
 }
Ejemplo n.º 38
0
        public void AssignAlphanumericFails(UInt64 x)
        {
            MutableString ms = new MutableString();

            Assert.That(() => AlphanumericUtils.AssignAlphanumeric(ms, x), Throws.TypeOf <ArgumentException>());
        }
Ejemplo n.º 39
0
        private bool LoadFromPath(Scope globalScope, object self, string /*!*/ path, RubyEncoding /*!*/ pathEncoding, LoadFlags flags, out object loaded)
        {
            Assert.NotNull(pathEncoding, path);

            string[] sourceFileExtensions;
            if ((flags & LoadFlags.AnyLanguage) != 0)
            {
                sourceFileExtensions = DomainManager.Configuration.GetFileExtensions();
            }
            else
            {
                sourceFileExtensions = DomainManager.Configuration.GetFileExtensions(_context);
            }

            IList <ResolvedFile> files = FindFile(path, (flags & LoadFlags.AppendExtensions) != 0, sourceFileExtensions);

            if (files.Count == 0)
            {
                // MRI: doesn't throw an exception if the path is in $" (performs resolution first though):
                if (AlreadyLoaded(path, null, flags, sourceFileExtensions))
                {
                    loaded = null;
                    return(false);
                }
                throw RubyExceptions.CreateLoadError(String.Format("no such file to load -- {0}", path));
            }

            ResolvedFile file = files.First();

            string pathWithExtension = path;

            if (file.AppendedExtension != null)
            {
                pathWithExtension += file.AppendedExtension;
            }

            if (AlreadyLoaded(path, files, flags) || _unfinishedFiles.Contains(file.Path))
            {
                if ((flags & LoadFlags.ResolveLoaded) != 0)
                {
                    if (file.SourceUnit != null)
                    {
                        Scope loadedScope;
                        if (!LoadedScripts.TryGetValue(file.Path, out loadedScope))
                        {
                            throw RubyExceptions.CreateLoadError(String.Format("no such file to load -- {0}", file.Path));
                        }
                        loaded = loadedScope;
                    }
                    else
                    {
                        loaded = Platform.LoadAssemblyFromPath(file.Path);
                    }
                }
                else
                {
                    loaded = null;
                }
                return(false);
            }

            try {
                // save path as is, no canonicalization nor combination with an extension or directory:
                _unfinishedFiles.Push(file.Path);

                if (file.SourceUnit != null)
                {
                    AddScriptLines(file.SourceUnit);

                    ScriptCode compiledCode;
                    if (file.SourceUnit.LanguageContext == _context)
                    {
                        compiledCode = CompileRubySource(file.SourceUnit, flags);
                    }
                    else
                    {
                        compiledCode = file.SourceUnit.Compile();
                    }
                    loaded = Execute(globalScope, compiledCode);
                }
                else
                {
                    Debug.Assert(file.Path != null);
                    try {
                        Assembly assembly = Platform.LoadAssemblyFromPath(file.Path);
                        DomainManager.LoadAssembly(assembly);
                        loaded = assembly;
                    } catch (Exception e) {
                        throw RubyExceptions.CreateLoadError(e);
                    }
                }

                FileLoaded(MutableString.Create(file.Path, pathEncoding), flags);
            } finally {
                _unfinishedFiles.Pop();
            }

            return(true);
        }
Ejemplo n.º 40
0
 public static void nativeTabBarSetTabBadge(RubyModule /*!*/ self, int index, MutableString /*!*/ val)
 {
 }
Ejemplo n.º 41
0
 internal static MutableString /*!*/ Bytes2Hex(byte[] /*!*/ bytes)
 {
     // TODO (opt): see also OpenSSL
     return(MutableString.CreateAscii(System.BitConverter.ToString(bytes).Replace("-", "").ToLowerInvariant()));
 }
Ejemplo n.º 42
0
        public static int ConnectNonBlocking(RubyContext /*!*/ context, RubySocket /*!*/ self, MutableString sockaddr)
        {
            bool blocking = self.Socket.Blocking;

            try {
                self.Socket.Blocking = false;
                return(Connect(context, self, sockaddr));
            } finally {
                // Reset the blocking
                self.Socket.Blocking = blocking;
            }
        }
Ejemplo n.º 43
0
 public static MutableString /*!*/ Finish(RubyContext /*!*/ context, Base /*!*/ self)
 {
     byte[] input = self._buffer.ConvertToBytes();
     byte[] hash  = self._algorithm.ComputeHash(input);
     return(MutableString.CreateBinary(hash));
 }
Ejemplo n.º 44
0
 public static void Reinitialize(StringScanner /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ scan, [Optional] object ignored)
 {
     self.ScanString = scan;
     self.Reset();
 }
Ejemplo n.º 45
0
 public static new int Send(ConversionStorage <int> /*!*/ fixnumCast,
                            RubyBasicSocket /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ message, object flags,
                            [DefaultProtocol, NotNull] MutableString /*!*/ to)
 {
     return(RubyBasicSocket.Send(fixnumCast, self, message, flags, to));
 }
Ejemplo n.º 46
0
 public static MutableString SetString(RubyContext /*!*/ context, StringScanner /*!*/ self, [NotNull] MutableString /*!*/ str)
 {
     self.ScanString = (MutableString)KernelOps.Freeze(context, MutableString.Create(str));
     self.Reset();
     return(str);
 }
Ejemplo n.º 47
0
 public static TCPServer /*!*/ CreateTCPServer(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast,
                                               RubyClass /*!*/ self, [DefaultProtocol] MutableString hostname, [DefaultParameterValue(null)] object port)
 {
     return(new TCPServer(self.Context, CreateSocket(stringCast, fixnumCast, hostname, port)));
 }
Ejemplo n.º 48
0
 public StringScanner(RubyClass /*!*/ rubyClass)
     : base(rubyClass)
 {
     _scanString = MutableString.FrozenEmpty;
 }
Ejemplo n.º 49
0
        private void AddBacktrace(IEnumerable <StackFrame> stackTrace, int skipFrames, bool skipInterpreterRunMethod)
        {
            if (stackTrace != null)
            {
                foreach (var frame in InterpretedFrame.GroupStackFrames(stackTrace))
                {
                    string methodName, file;
                    int    line;

                    if (_interpretedFrames != null && _interpretedFrameIndex < _interpretedFrames.Count &&
                        InterpretedFrame.IsInterpretedFrame(frame.GetMethod()))
                    {
                        if (skipInterpreterRunMethod)
                        {
                            skipInterpreterRunMethod = false;
                            continue;
                        }

                        InterpretedFrameInfo info = _interpretedFrames[_interpretedFrameIndex++];

                        if (info.DebugInfo != null)
                        {
                            file = info.DebugInfo.FileName;
                            line = info.DebugInfo.StartLine;
                        }
                        else
                        {
                            file = null;
                            line = 0;
                        }
                        methodName = info.MethodName;

                        // TODO: We need some more general way to recognize and parse non-Ruby interpreted frames
                        TryParseRubyMethodName(ref methodName, ref file, ref line);

                        if (methodName == InterpretedCallSiteName)
                        {
                            // ignore ruby interpreted call sites
                            continue;
                        }
                    }
                    else if (TryGetStackFrameInfo(frame, out methodName, out file, out line))
                    {
                        // special case: the frame will be added with the next frame's source info:
                        if (line == NextFrameLine)
                        {
                            _nextFrameMethodName = methodName;
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }

                    if (_nextFrameMethodName != null)
                    {
                        if (skipFrames == 0)
                        {
                            _trace.Add(MutableString.Create(FormatFrame(file, line, _nextFrameMethodName), _encoding));
                        }
                        else
                        {
                            skipFrames--;
                        }
                        _nextFrameMethodName = null;
                    }

                    if (skipFrames == 0)
                    {
                        _trace.Add(MutableString.Create(FormatFrame(file, line, methodName), _encoding));
                    }
                    else
                    {
                        skipFrames--;
                    }
                }
            }
        }
Ejemplo n.º 50
0
 public static MutableString ToString(StringScanner /*!*/ self)
 {
     return(MutableString.Create(self.ToString(), self._scanString.Encoding));
 }
Ejemplo n.º 51
0
 public static Exception /*!*/ Create(RubyClass /*!*/ self, [DefaultParameterValue(null)] object message)
 {
     return(RubyExceptionData.InitializeException(new SocketException(0), message ?? MutableString.CreateAscii("SocketError")));
 }
Ejemplo n.º 52
0
 public static StringScanner Concat(StringScanner /*!*/ self, MutableString str)
 {
     self.ScanString.Append(str);
     return(self);
 }
Ejemplo n.º 53
0
 public static int F(MutableString p)
 {
     return(3);
 }
Ejemplo n.º 54
0
 protected Base(HashAlgorithm /*!*/ algorithm)
 {
     Assert.NotNull(algorithm);
     _algorithm = algorithm;
     _buffer    = MutableString.CreateBinary();
 }
Ejemplo n.º 55
0
 public void L3([DefaultProtocol] MutableString a, [DefaultProtocol, NotNull] string b)
 {
 }
Ejemplo n.º 56
0
 public static MutableString /*!*/ HexEncode(RubyModule /*!*/ self, [NotNull] MutableString /*!*/ str)
 {
     // TODO:
     throw new NotImplementedException();
 }
Ejemplo n.º 57
0
 public static double ConvertStringToFloat(RubyContext /*!*/ context, MutableString /*!*/ value)
 {
     return(RubyOps.ConvertStringToFloat(context, value.ConvertToString()));
 }
Ejemplo n.º 58
0
 internal static MutableString /*!*/ HexEncode(MutableString /*!*/ str)
 {
     return(Bytes2Hex(str.ConvertToBytes()));
 }
Ejemplo n.º 59
0
 public static Base /*!*/ Reset(RubyContext /*!*/ context, Base /*!*/ self)
 {
     self._buffer = MutableString.CreateBinary();
     self._algorithm.Initialize();
     return(self);
 }
Ejemplo n.º 60
0
 public static Base /*!*/ Update(RubyContext /*!*/ context, Base /*!*/ self, MutableString str)
 {
     self._buffer.Append(str);
     return(self);
 }