public static bool AreIdentical(ConversionStorage<MutableString>/*!*/ toPath, RubyModule/*!*/ self, object path1, object path2) { FileSystemInfo info1, info2; return RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path1)), out info1) && RubyFileOps.RubyStatOps.TryCreate(self.Context, self.Context.DecodePath(Protocols.CastToPath(toPath, path2)), out info2) && RubyFileOps.RubyStatOps.AreIdentical(self.Context, info1, info2); }
public static MutableString/*!*/ ToPrintedString(ConversionStorage<MutableString>/*!*/ tosConversion, object obj) { if (obj == null) { return MutableString.CreateAscii("nil"); } else { return Protocols.ConvertToString(tosConversion, obj); } }
public static RubyArray GetGroup(ConversionStorage<int>/*!*/ fixnumCast, MatchData/*!*/ self, [NotNull]Range/*!*/ range) { int begin, count; if (!IListOps.NormalizeRange(fixnumCast, self.Groups.Count, range, out begin, out count)) { return null; } return GetGroup(fixnumCast.Context, self, begin, count); }
public static int Connect(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, RubyContext/*!*/ context, UDPSocket/*!*/ self, object hostname, object port) { string strHostname = ConvertToHostString(stringCast, context, hostname); int iPort = ConvertToPortNum(stringCast, fixnumCast, context, port); self.Socket.Connect(strHostname, iPort); return 0; }
public static void PrintFormatted( StringFormatterSiteStorage/*!*/ storage, ConversionStorage<MutableString>/*!*/ stringCast, BinaryOpStorage/*!*/ writeStorage, object/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ format, params object[]/*!*/ args) { KernelOps.PrintFormatted(storage, stringCast, writeStorage, null, self, format, args); }
public static long CastToInt64Unchecked(ConversionStorage<IntegerValue>/*!*/ integerConversion, object obj) { if (obj == null) { throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer"); } return CastToInteger(integerConversion, obj).ToInt64(); }
public static TCPServer/*!*/ Reinitialize(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, TCPServer/*!*/ self, [DefaultProtocol]MutableString remoteHost, object remotePort, [DefaultProtocol]MutableString localHost, object localPort) { self.Socket = CreateSocket(remoteHost, ConvertToPortNum(stringCast, fixnumCast, remotePort)); BindLocalEndPoint(self, localHost, ConvertToPortNum(stringCast, fixnumCast, localPort)); return self; }
public static TCPSocket/*!*/ CreateTCPSocket(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ remoteHost, object remotePort) { int port = ConvertToPortNum(stringCast, fixnumCast, self.Context, remotePort); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(remoteHost.ConvertToString(), port); return new TCPSocket(self.Context, socket); }
public static Object Scan(ConversionStorage<MutableString>/*!*/ toMutableStringStorage, RespondToStorage/*!*/ respondsTo, BinaryOpStorage/*!*/ readIOStorage, BlockParam block, RubyModule/*!*/ self, Object/*!*/ source, Hash/*!*/ options) { Object elementContent; if (!self.TryGetConstant(null, "ElementContent", out elementContent) && !(elementContent is Hash)) { throw new Exception("Hpricot::ElementContent is missing or it is not an Hash"); } var scanner = new HpricotScanner(toMutableStringStorage, readIOStorage, block); return scanner.Scan(source, options, elementContent as Hash); }
public static RubyArray/*!*/ ReceiveFromNonBlocking(ConversionStorage<int>/*!*/ fixnumCast, IPSocket/*!*/ self, int length) { bool blocking = self.Socket.Blocking; try { self.Socket.Blocking = false; return ReceiveFrom(fixnumCast, self, length, null); } finally { // Reset the blocking self.Socket.Blocking = blocking; } }
public static RubyArray/*!*/ ReceiveFromNonBlocking(ConversionStorage<int>/*!*/ fixnumCast, RubyContext/*!*/ context, IPSocket/*!*/ self, int length, object/*Numeric*/ flags) { bool blocking = self.Socket.Blocking; try { self.Socket.Blocking = false; return ReceiveFrom(fixnumCast, context, self, length, flags); } finally { // Reset the blocking self.Socket.Blocking = blocking; } }
public static int Bind(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, RubyContext/*!*/ context, UDPSocket/*!*/ self, object hostNameOrAddress, object port) { int iPort = ConvertToPortNum(stringCast, fixnumCast, context, port); IPAddress address = (hostNameOrAddress != null) ? GetHostAddress(ConvertToHostString(stringCast, context, hostNameOrAddress)) : IPAddress.Loopback; IPEndPoint ep = new IPEndPoint(address, iPort); self.Socket.Bind(ep); return 0; }
public static RubyIO/*!*/ CreateFile( ConversionStorage<int?>/*!*/ toInt, ConversionStorage<IDictionary<object, object>>/*!*/ toHash, ConversionStorage<MutableString>/*!*/ toStr, RubyClass/*!*/ self, object descriptor, [Optional]object optionsOrMode, [DefaultParameterValue(null), DefaultProtocol]IDictionary<object, object> options) { return Reinitialize(toInt, toHash, toStr, new RubyIO(self.Context), descriptor, optionsOrMode, options); }
public static TCPSocket /*!*/ CreateTCPSocket(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast, RubyClass /*!*/ self, [DefaultProtocol] MutableString remoteHost, object remotePort, [DefaultProtocol] MutableString localHost, object localPort) { return(BindLocalEndPoint( CreateTCPSocket(stringCast, fixnumCast, self, remoteHost, remotePort, 0), localHost, ConvertToPortNum(stringCast, fixnumCast, localPort) )); }
public static int RemoveDirectory(ConversionStorage <MutableString> /*!*/ toPath, RubyClass /*!*/ self, object dirname) { string strDir = self.Context.DecodePath(Protocols.CastToPath(toPath, dirname)); try { self.Context.Platform.DeleteDirectory(strDir, false); } catch (Exception ex) { throw ToRubyException(ex, strDir, DirectoryOperation.Delete); } return(0); }
internal static void ReportWarning(BinaryOpStorage /*!*/ writeStorage, ConversionStorage <MutableString> /*!*/ tosConversion, object message) { if (writeStorage.Context.Verbose != null) { var output = writeStorage.Context.StandardErrorOutput; // MRI: unlike Kernel#puts this outputs \n even if the message ends with \n: var site = writeStorage.GetCallSite("write", 1); site.Target(site, output, PrintOps.ToPrintedString(tosConversion, message)); PrintOps.PutsEmptyLine(writeStorage, output); } }
public static MutableString /*!*/ ToPrintedString(ConversionStorage <MutableString> /*!*/ tosConversion, object obj) { if (obj == null) { return(MutableString.CreateAscii("nil")); } else { return(Protocols.ConvertToString(tosConversion, obj)); } }
public static object SetLength(ConversionStorage <int> /*!*/ fixnumCast, StringIO /*!*/ self, object lengthObj) { int length = Protocols.CastToFixnum(fixnumCast, lengthObj); if (length < 0) { throw RubyExceptions.CreateEINVAL("negative length"); } self.GetWritableContent().SetByteCount(length); return(lengthObj); }
public static Hash/*!*/ CreateSubclass(ConversionStorage<IList>/*!*/ toAry, RubyClass/*!*/ self, [NotNull]IList/*!*/ list) { Hash result = Hash.CreateInstance(self); var toArySite = toAry.GetSite(TryConvertToArrayAction.Make(toAry.Context)); foreach (object item in list) { IList pair = toArySite.Target(toArySite, item); if (pair != null && pair.Count >= 1 && pair.Count <= 2) { RubyUtils.SetHashElement(self.Context, result, pair[0], (pair.Count == 2) ? pair[1] : null); } } return result; }
public static TCPSocket/*!*/ CreateTCPSocket(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, RubyClass/*!*/ self, [DefaultProtocol]MutableString remoteHost, object remotePort, [Optional]int localPort) { // Not sure what the semantics should be in this case but we make sure not to blow up. // Real-world code (Server.connect_to in memcache.rb in the memcache-client gem) does do "TCPSocket.new(host, port, 0)" if (localPort != 0) { throw new NotImplementedError(); } return new TCPSocket(self.Context, CreateSocket(remoteHost, ConvertToPortNum(stringCast, fixnumCast, remotePort))); }
public static TCPSocket/*!*/ CreateTCPSocket(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, RubyClass/*!*/ self, [DefaultProtocol]MutableString remoteHost, object remotePort, [DefaultProtocol]MutableString localHost, object localPort) { return BindLocalEndPoint( CreateTCPSocket(stringCast, fixnumCast, self, remoteHost, remotePort, 0), localHost, ConvertToPortNum(stringCast, fixnumCast, localPort) ); }
public static object Zip(CallSiteStorage <EachSite> /*!*/ each, ConversionStorage <IList> /*!*/ tryToA, BlockParam block, object self, params object[] /*!*/ args) { // Call to_a on each argument IList[] otherArrays = new IList[args.Length]; for (int i = 0; i < args.Length; i++) { otherArrays[i] = (args[i] as IList) ?? Protocols.TryConvertToArray(tryToA, args[i]); } return(Zip(each, tryToA, block, self, otherArrays)); }
public static int Bind(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, RubyContext/*!*/ context, UDPSocket/*!*/ self, object hostname, object port) { int iPort = ConvertToPortNum(stringCast, fixnumCast, context, port); if (hostname == null) { hostname = MutableString.Create("localhost"); } MutableString address = GetAddressInternal(context, hostname); IPEndPoint ep = new IPEndPoint(IPAddress.Parse(address.ConvertToString()), iPort); self.Socket.Bind(ep); return 0; }
public static object LoadStream(ConversionStorage <MutableString> /*!*/ toStr, RespondToStorage /*!*/ respondTo, UnaryOpStorage /*!*/ newStorage, BinaryOpStorage /*!*/ addStorage, RubyScope /*!*/ scope, RubyModule /*!*/ self, object io) { RubyConstructor rc = MakeConstructor(scope.GlobalScope, GetStream(toStr, respondTo, io)); // TODO: only if io was converted to a string: io = CreateDefaultStream(newStorage, scope, self); AddDocumentsToStream(addStorage, rc, io); return(io); }
public static RubyArray/*!*/ ReceiveFrom(ConversionStorage<int>/*!*/ conversionStorage, RubyContext/*!*/ context, IPSocket/*!*/ self, int length, [DefaultParameterValue(null)]object/*Numeric*/ flags) { SocketFlags sFlags = ConvertToSocketFlag(conversionStorage, context, flags); byte[] buffer = new byte[length]; EndPoint fromEP = new IPEndPoint(IPAddress.Any, 0); int received = self.Socket.ReceiveFrom(buffer, sFlags, ref fromEP); MutableString str = MutableString.CreateBinary(); str.Append(buffer, 0, received); context.SetObjectTaint(str, true); return RubyOps.MakeArray2(str, GetAddressArray(context, fromEP)); }
private static MutableString Transform(ConversionStorage<MutableString> toS, IDictionary self, GeneratorState state, int depth) { byte[] objectNl = state.ObjectNl.ToByteArray(); byte[] indent = Helpers.Repeat(state.Indent.ToByteArray(), depth + 1); byte[] spaceBefore = state.SpaceBefore.ToByteArray(); byte[] space = state.Space.ToByteArray(); int subDepth = depth + 1; MutableString result = MutableString.CreateBinary(2 + self.Count * (12 + indent.Length + spaceBefore.Length + space.Length)); RubyContext context = toS.Context; result.Append((byte)'{'); result.Append(objectNl); if (self.Count > 0) { MutableString json; int i = 0; foreach (DictionaryEntry kv in self) { if (i > 0) { result.Append(objectNl); } if (objectNl.Length != 0) { result.Append(indent); } json = Generator.ToJson(context, Protocols.ConvertToString(toS, kv.Key), state, subDepth); result.Append(json); context.TaintObjectBy<Object>(result, json); result.Append(spaceBefore); result.Append((byte)':'); result.Append(space); json = Generator.ToJson(context, kv.Value, state, subDepth); result.Append(json); context.TaintObjectBy<Object>(result, json); if (++i < self.Count) { result.Append(','); } } if (objectNl.Length != 0) { result.Append(objectNl); if (indent.Length != 0) { for (int n = 0; n < depth; n++) { result.Append(indent); } } } } result.Append((byte)'}'); return result; }
public static TCPSocket /*!*/ CreateTCPSocket(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast, RubyClass /*!*/ self, [DefaultProtocol] MutableString remoteHost, object remotePort, [Optional] int localPort) { // Not sure what the semantics should be in this case but we make sure not to blow up. // Real-world code (Server.connect_to in memcache.rb in the memcache-client gem) does do "TCPSocket.new(host, port, 0)" if (localPort != 0) { throw new NotImplementedError(); } return(new TCPSocket(self.Context, CreateSocket(remoteHost, ConvertToPortNum(stringCast, fixnumCast, remotePort)))); }
public static MutableString JsonCreate(ConversionStorage <IntegerValue> /*!*/ integerConversion, RubyClass /*!*/ self, Hash /*!*/ creatable) { RubyArray raw = (RubyArray)creatable[MutableString.CreateAscii("raw")]; MutableStringStream stream = new MutableStringStream(); for (int i = 0; i < raw.Count; i++) { stream.WriteByte(unchecked ((byte)Protocols.CastToUInt32Unchecked(integerConversion, raw[i]))); } return(stream.String); }
public static int Bind(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast, UDPSocket /*!*/ self, object hostNameOrAddress, object port) { int iPort = ConvertToPortNum(stringCast, fixnumCast, port); IPAddress address = (hostNameOrAddress != null) ? GetHostAddress(ConvertToHostString(stringCast, hostNameOrAddress)) : IPAddress.Loopback; IPEndPoint ep = new IPEndPoint(address, iPort); self.Socket.Bind(ep); return(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; }
public static RubyArray /*!*/ ReceiveFromNonBlocking(ConversionStorage <int> /*!*/ fixnumCast, IPSocket /*!*/ self, int length) { bool blocking = self.Socket.Blocking; try { self.Socket.Blocking = false; return(ReceiveFrom(fixnumCast, self, length, null)); } finally { // Reset the blocking self.Socket.Blocking = blocking; } }
public static object Open(ConversionStorage <MutableString> /*!*/ toPath, BlockParam block, RubyClass /*!*/ self, object dirname) { RubyDir rd = new RubyDir(self, Protocols.CastToPath(toPath, dirname)); try { object result; block.Yield(rd, out result); return(result); } finally { Close(rd); } }
/// <summary> /// Step through a Range of Strings. /// </summary> /// <remarks> /// This method requires step to be a Fixnum. /// It uses a hybrid string comparison to prevent infinite loops and calls String#succ to get each item in the range. /// </remarks> private static object StepString( ConversionStorage <MutableString> /*!*/ stringCast, BinaryOpStorage /*!*/ comparisonStorage, BinaryOpStorage /*!*/ lessThanStorage, BinaryOpStorage /*!*/ greaterThanStorage, UnaryOpStorage /*!*/ succStorage, BlockParam block, Range /*!*/ self, MutableString begin, MutableString end, int step) { CheckStep(step); object result; MutableString item = begin; int comp; var succSite = succStorage.GetCallSite("succ"); while ((comp = Protocols.Compare(comparisonStorage, lessThanStorage, greaterThanStorage, item, end)) < 0) { if (block == null) { throw RubyExceptions.NoBlockGiven(); } if (block.Yield(item, out result)) { return(result); } for (int i = 0; i < step; i++) { item = Protocols.CastToString(stringCast, succSite.Target(succSite, item)); } if (item.Length > end.Length) { return(self); } } if (comp == 0 && !self.ExcludeEnd) { if (block == null) { throw RubyExceptions.NoBlockGiven(); } if (block.Yield(item, out result)) { return(result); } } return(self); }
public static Object Scan(ConversionStorage <MutableString> /*!*/ toMutableStringStorage, RespondToStorage /*!*/ respondsTo, BinaryOpStorage /*!*/ readIOStorage, BlockParam block, RubyModule /*!*/ self, Object /*!*/ source, Hash /*!*/ options) { Object elementContent; if (!self.TryGetConstant(null, "ElementContent", out elementContent) && !(elementContent is Hash)) { throw new Exception("Hpricot::ElementContent is missing or it is not an Hash"); } var scanner = new HpricotScanner(toMutableStringStorage, readIOStorage, block); return(scanner.Scan(source, options, elementContent as Hash)); }
public static object NullableSize(ConversionStorage <MutableString> /*!*/ toPath, RubyModule /*!*/ self, object path) { FileSystemInfo fsi; if (RubyFileOps.RubyStatOps.TryCreate(self.Context, Protocols.CastToPath(toPath, path).ConvertToString(), out fsi)) { return(RubyFileOps.RubyStatOps.NullableSize(fsi)); } else { return(null); } }
public static MutableString /*!*/ ReceiveNonBlocking(ConversionStorage <int> /*!*/ fixnumCast, RubyBasicSocket /*!*/ self, [DefaultProtocol] int length, [DefaultParameterValue(null)] object flags) { bool blocking = self.Socket.Blocking; try { self.Socket.Blocking = false; return(Receive(fixnumCast, self, length, flags)); } finally { // Reset the blocking self.Socket.Blocking = blocking; } }
public static object Step( ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast, RespondToStorage /*!*/ respondToStorage, BinaryOpStorage /*!*/ comparisonStorage, BinaryOpStorage /*!*/ lessThanStorage, BinaryOpStorage /*!*/ lessThanEqualsStorage, BinaryOpStorage /*!*/ greaterThanStorage, BinaryOpStorage /*!*/ equalsStorage, BinaryOpStorage /*!*/ addStorage, UnaryOpStorage /*!*/ succStorage, BlockParam block, Range /*!*/ self, [Optional] object step) { if (step == Missing.Value) { step = ClrInteger.One; } // We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is. // This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does. if (self.Begin is int && self.End is int) { // self.begin is Fixnum; directly call item = item + 1 instead of succ int intStep = Protocols.CastToFixnum(fixnumCast, step); return(StepFixnum(block, self, (int)self.Begin, (int)self.End, intStep)); } else if (self.Begin is MutableString) { // self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings int intStep = Protocols.CastToFixnum(fixnumCast, step); return(StepString(stringCast, comparisonStorage, lessThanStorage, greaterThanStorage, succStorage, block, self, (MutableString)self.Begin, (MutableString)self.End, intStep )); } else if (succStorage.Context.IsInstanceOf(self.Begin, succStorage.Context.GetClass(typeof(Numeric)))) { // self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare return(StepNumeric(lessThanStorage, lessThanEqualsStorage, equalsStorage, addStorage, block, self, self.Begin, self.End, step )); } else { // self.begin is not Numeric or String; just invoke item.succ and item <=> self.end CheckBegin(respondToStorage, self.Begin); int intStep = Protocols.CastToFixnum(fixnumCast, step); return(StepObject(comparisonStorage, lessThanStorage, greaterThanStorage, equalsStorage, succStorage, block, self, self.Begin, self.End, intStep )); } }
public static int SysWrite(BinaryOpStorage /*!*/ writeStorage, ConversionStorage <MutableString> /*!*/ tosConversion, RubyContext /*!*/ context, RubyIO /*!*/ self, [NotNull] MutableString /*!*/ val) { RubyBufferedStream stream = self.GetWritableStream(); if (stream.DataBuffered) { PrintOps.ReportWarning(writeStorage, tosConversion, MutableString.CreateAscii("syswrite for buffered IO")); } int bytes = Write(self, val); self.Flush(); return(bytes); }
public static MutableString /*!*/ ToMutableString(ConversionStorage <MutableString> /*!*/ tosConversion, IDictionary <object, object> /*!*/ self) { using (IDisposable handle = RubyUtils.InfiniteToSTracker.TrackObject(self)) { if (handle == null) { return(MutableString.CreateAscii("{...}")); } else { return(IListOps.Join(tosConversion, ToArray(self))); } } }
public static RubyArray /*!*/ ReceiveFrom(ConversionStorage <int> /*!*/ fixnumCast, RubySocket /*!*/ self, int length, object /*Numeric*/ flags) { SocketFlags sFlags = ConvertToSocketFlag(fixnumCast, flags); byte[] buffer = new byte[length]; EndPoint fromEP = new IPEndPoint(IPAddress.Any, 0); int received = self.Socket.ReceiveFrom(buffer, sFlags, ref fromEP); MutableString str = MutableString.CreateBinary(); str.Append(buffer, 0, received); str.IsTainted = true; return(RubyOps.MakeArray2(str, self.GetAddressArray(fromEP))); }
public void Dir1() { RubyClass dir = Context.GetClass(typeof(RubyDir)); Pal1 pal = (Pal1)Context.Platform; var sjis = RubyEncoding.KCodeSJIS.StrictEncoding.GetBytes("ホ"); var toPath = new ConversionStorage <MutableString>(Context); // transcode to UTF8 if no KCODE specified Context.KCode = null; RubyDir.MakeDirectory(toPath, dir, MutableString.CreateBinary(new byte[] { 0xce, 0xa3 }, RubyEncoding.Binary), null); Assert(pal.Entries["Σ"]); pal.Entries.Clear(); // transcode to UTF8 if no KCODE specified Context.KCode = null; RubyDir.MakeDirectory(toPath, dir, MutableString.CreateMutable("ホア", RubyEncoding.KCodeSJIS), null); Assert(pal.Entries["α"]); Assert(FileTest.IsDirectory(toPath, Context.KernelModule, MutableString.CreateMutable("ホア", RubyEncoding.KCodeSJIS))); Assert(FileTest.IsDirectory(toPath, Context.KernelModule, MutableString.CreateMutable("α", RubyEncoding.KCodeUTF8))); pal.Entries.Clear(); // transcode to KCODE if specified Context.KCode = RubyEncoding.KCodeUTF8; RubyDir.MakeDirectory(toPath, dir, MutableString.CreateBinary(new byte[] { 0xce, 0xa3 }, RubyEncoding.KCodeSJIS), null); Assert(pal.Entries["Σ"]); pal.Entries.Clear(); // transcode to KCODE if specified Context.KCode = RubyEncoding.KCodeSJIS; RubyDir.MakeDirectory(toPath, dir, MutableString.CreateBinary(sjis, RubyEncoding.Binary), null); Assert(pal.Entries["ホ"]); pal.Entries.Clear(); // ignore entries whose name cannot be encoded using the current KCODE Context.KCode = RubyEncoding.KCodeSJIS; AssertExceptionThrown <EncoderFallbackException>(() => RubyEncoding.KCodeSJIS.StrictEncoding.GetBytes("Ԋ")); pal.Entries["Ԋ"] = true; pal.Entries["ホ"] = true; var entries = RubyDir.GetEntries(toPath, dir, MutableString.CreateEmpty()); Assert(entries.Count == 3); foreach (MutableString entry in entries) { Assert(entry.Encoding == RubyEncoding.KCodeSJIS); } Assert(((MutableString)entries[0]).Equals(MutableString.CreateAscii("."))); Assert(((MutableString)entries[1]).Equals(MutableString.CreateAscii(".."))); Assert(((MutableString)entries[2]).Equals(MutableString.Create("ホ", RubyEncoding.KCodeSJIS))); }
public static MutableString Receive(ConversionStorage <int> /*!*/ fixnumCast, RubyBasicSocket /*!*/ self, [DefaultProtocol] int length, [DefaultParameterValue(null)] object flags) { SocketFlags sFlags = ConvertToSocketFlag(fixnumCast, flags); byte[] buffer = new byte[length]; int received = self.Socket.Receive(buffer, 0, length, sFlags); MutableString str = MutableString.CreateBinary(received); str.Append(buffer, 0, received); str.IsTainted = true; return(str); }
public static object CreateArray(ConversionStorage<Union<IList, int>>/*!*/ toAryToInt, BlockParam block, RubyClass/*!*/ self, [NotNull]object/*!*/ arrayOrSize) { var site = toAryToInt.GetSite(CompositeConversionAction.Make(toAryToInt.Context, CompositeConversion.ToAryToInt)); var union = site.Target(site, arrayOrSize); if (union.First != null) { // block ignored return CreateArray(union.First); } else if (block != null) { return CreateArray(block, union.Second); } else { return CreateArray(self, union.Second, null); } }
public static Hash /*!*/ CreateSubclass(ConversionStorage <IList> /*!*/ toAry, RubyClass /*!*/ self, [NotNull] IList /*!*/ list) { Hash result = Hash.CreateInstance(self); var toArySite = toAry.GetSite(TryConvertToArrayAction.Make(toAry.Context)); foreach (object item in list) { IList pair = toArySite.Target(toArySite, item); if (pair != null && pair.Count >= 1 && pair.Count <= 2) { RubyUtils.SetHashElement(self.Context, result, pair[0], (pair.Count == 2) ? pair[1] : null); } } return(result); }
public static RubyArray /*!*/ Coerce(ConversionStorage <double> /*!*/ tof1, ConversionStorage <double> /*!*/ tof2, object self, object other) { var context = tof1.Context; if (context.GetClassOf(self) == context.GetClassOf(other)) { return(RubyOps.MakeArray2(other, self)); } var site1 = tof1.GetSite(ConvertToFAction.Make(context)); var site2 = tof2.GetSite(ConvertToFAction.Make(context)); return(RubyOps.MakeArray2(site1.Target(site1, other), site2.Target(site2, self))); }
internal static bool NormalizeSubstringRange(ConversionStorage<int>/*!*/ fixnumCast, Range/*!*/ range, int length, out int begin, out int count) { begin = Protocols.CastToFixnum(fixnumCast, range.Begin); int end = Protocols.CastToFixnum(fixnumCast, range.End); begin = IListOps.NormalizeIndex(length, begin); if (begin < 0 || begin > length) { count = 0; return false; } end = IListOps.NormalizeIndex(length, end); count = range.ExcludeEnd ? end - begin : end - begin + 1; return true; }
public static MutableString ToJson(ConversionStorage<MutableString> toS, IDictionary self, GeneratorState state, int? depth) { MutableString result; RubyContext context = toS.Context; if (state == null) { MutableString json; result = MutableString.CreateMutable(2 + Math.Max(self.Count * 12, 0), RubyEncoding.Default); result.Append('{'); if (self.Count > 0) { int i = 0; foreach (DictionaryEntry kv in self) { // TODO: added state and depth json = Generator.ToJson(context, Protocols.ConvertToString(toS, kv.Key), null, 0); result.Append(json); context.TaintObjectBy<Object>(result, json); result.Append(':'); json = Generator.ToJson(context, kv.Value, null, 0); result.Append(json); context.TaintObjectBy<Object>(result, json); if (++i < self.Count) { result.Append(','); } } } result.Append('}'); } else { GeneratorState.Ensure(state); if (state.CheckCircular) { if (state.Seen(context, self)) { Helpers.ThrowCircularDataStructureException("circular data structures not supported!"); } state.Remember(context, self); result = Transform(toS, self, state, depth.HasValue ? depth.Value : 0); state.Forget(context, self); } else { result = Transform(toS, self, state, depth.HasValue ? depth.Value : 0); } } return result; }
public static object Parse(ConversionStorage <MutableString> /*!*/ toStr, RespondToStorage /*!*/ respondTo, RubyModule /*!*/ self, object io) { using (Stream stream = GetStream(toStr, respondTo, io)) { foreach (Node obj in MakeComposer(self.Context, stream)) { // TODO: the enumerator shouldn't return null: if (obj == null) { break; } return(obj); } } return(ScriptingRuntimeHelpers.False); }
public static int Send(ConversionStorage <int> /*!*/ fixnumCast, ConversionStorage <MutableString> /*!*/ stringCast, RubyBasicSocket /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ message, object flags, object hostNameOrAddress, object port) { Protocols.CheckSafeLevel(fixnumCast.Context, 4, "send"); int iPort = ConvertToPortNum(stringCast, fixnumCast, port); SocketFlags sFlags = ConvertToSocketFlag(fixnumCast, flags); // Convert the parameters IPAddress address = (hostNameOrAddress != null) ? GetHostAddress(ConvertToHostString(stringCast, hostNameOrAddress)) : IPAddress.Loopback; EndPoint toEndPoint = new IPEndPoint(address, iPort); return(self.Socket.SendTo(message.ConvertToBytes(), sFlags, toEndPoint)); }
internal static bool NormalizeRange(ConversionStorage<int>/*!*/ fixnumCast, int listCount, Range/*!*/ range, out int begin, out int count) { begin = Protocols.CastToFixnum(fixnumCast, range.Begin); int end = Protocols.CastToFixnum(fixnumCast, range.End); begin = NormalizeIndex(listCount, begin); if (begin < 0 || begin > listCount) { count = 0; return false; } end = NormalizeIndex(listCount, end); count = range.ExcludeEnd ? end - begin : end - begin + 1; return true; }
public static object CreateArray(ConversionStorage<int>/*!*/ conversionStorage, BlockParam block, RubyClass/*!*/ self, [NotNull]object/*!*/ arrayOrSize) { IList array = Protocols.AsArray(self.Context, arrayOrSize); if (array != null) { // block ignored return CreateArray(array); } int size = Protocols.CastToFixnum(conversionStorage, self.Context, arrayOrSize); if (block != null) { return CreateArray(block, size); } else { return CreateArray(self, size, null); } }
public static RubyFile/*!*/ Reinitialize( ConversionStorage<int?>/*!*/ toInt, ConversionStorage<IDictionary<object, object>>/*!*/ toHash, ConversionStorage<MutableString>/*!*/ toPath, ConversionStorage<MutableString>/*!*/ toStr, RubyFile/*!*/ self, object descriptorOrPath, [Optional]object optionsOrMode, [Optional]object optionsOrPermissions, [DefaultParameterValue(null), DefaultProtocol]IDictionary<object, object> options) { var context = self.Context; Protocols.TryConvertToOptions(toHash, ref options, ref optionsOrMode, ref optionsOrPermissions); var toIntSite = toInt.GetSite(TryConvertToFixnumAction.Make(toInt.Context)); IOInfo info = new IOInfo(); if (optionsOrMode != Missing.Value) { int? m = toIntSite.Target(toIntSite, optionsOrMode); info = m.HasValue ? new IOInfo((IOMode)m) : IOInfo.Parse(context, Protocols.CastToString(toStr, optionsOrMode)); } int permissions = 0; if (optionsOrPermissions != Missing.Value) { int? p = toIntSite.Target(toIntSite, optionsOrPermissions); if (!p.HasValue) { throw RubyExceptions.CreateTypeConversionError(context.GetClassName(optionsOrPermissions), "Integer"); } permissions = p.Value; } if (options != null) { info = info.AddOptions(toStr, options); } // TODO: permissions // descriptor or path: int? descriptor = toIntSite.Target(toIntSite, descriptorOrPath); if (descriptor.HasValue) { RubyIOOps.Reinitialize(self, descriptor.Value, info); } else { Reinitialize(self, Protocols.CastToPath(toPath, descriptorOrPath), info, permissions); } return self; }
public static MutableString /*!*/ PackInetSockAddr(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast, RubyClass /*!*/ self, object port, object hostNameOrAddress) { int iPort = ConvertToPortNum(stringCast, fixnumCast, port); IPAddress address = (hostNameOrAddress != null) ? GetHostAddress(ConvertToHostString(stringCast, hostNameOrAddress)) : IPAddress.Loopback; SocketAddress socketAddress = new IPEndPoint(address, iPort).Serialize(); var result = MutableString.CreateBinary(socketAddress.Size); for (int i = 0; i < socketAddress.Size; i++) { result.Append(socketAddress[i]); } return(result); }
public static RubyArray /*!*/ ReceiveFrom(ConversionStorage <int> /*!*/ conversionStorage, IPSocket /*!*/ self, int length, [DefaultParameterValue(null)] object /*Numeric*/ flags) { SocketFlags sFlags = ConvertToSocketFlag(conversionStorage, flags); byte[] buffer = new byte[length]; EndPoint fromEP = new IPEndPoint(IPAddress.Any, 0); int received = self.Socket.ReceiveFrom(buffer, sFlags, ref fromEP); MutableString str = MutableString.CreateBinary(); str.Append(buffer, 0, received); var context = conversionStorage.Context; str.IsTainted = true; return(RubyOps.MakeArray2(str, GetAddressArray(context, fromEP))); }
public static Hash/*!*/ CreateSubclass(ConversionStorage<IDictionary<object, object>>/*!*/ toHash, ConversionStorage<IList>/*!*/ toAry, RubyClass/*!*/ self, object listOrHash) { var toHashSite = toHash.GetSite(TryConvertToHashAction.Make(toHash.Context)); var hash = toHashSite.Target(toHashSite, listOrHash); if (hash != null) { return CreateSubclass(self, hash); } var toArySite = toAry.GetSite(TryConvertToArrayAction.Make(toAry.Context)); var array = toArySite.Target(toArySite, listOrHash); if (array != null) { return CreateSubclass(toAry, self, array); } throw RubyExceptions.CreateArgumentError("odd number of arguments for Hash"); }
public static Win32API /*!*/ Reinitialize( ConversionStorage <MutableString> /*!*/ toStr, Win32API /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ libraryName, [DefaultProtocol, NotNull] MutableString /*!*/ functionName, [NotNull] IList /*!*/ parameterTypes, [DefaultProtocol, NotNull] MutableString /*!*/ returnType) { return(self.Reinitialize( GetFunction(libraryName, functionName), MakeSignature(parameterTypes.Count, (i) => { var str = Protocols.CastToString(toStr, parameterTypes[i]); return str.IsEmpty ? (byte)0 : str.GetByte(0); }), returnType.IsEmpty ? ArgType.None : ToArgType(returnType.GetByte(0)) )); }
public static object Reinitialize(ConversionStorage<Union<IList, int>>/*!*/ toAryToInt, BlockParam block, RubyArray/*!*/ self, [NotNull]object/*!*/ arrayOrSize) { var context = toAryToInt.Context; var site = toAryToInt.GetSite(CompositeConversionAction.Make(context, CompositeConversion.ToAryToInt)); var union = site.Target(site, arrayOrSize); if (union.First != null) { // block ignored return Reinitialize(self, union.First); } else if (block != null) { return Reinitialize(block, self, union.Second); } else { return ReinitializeByRepeatedValue(context, self, union.Second, null); } }
public static int Send(ConversionStorage <int> /*!*/ fixnumCast, RubyBasicSocket /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ message, object flags, [DefaultProtocol, NotNull] MutableString /*!*/ to) { Protocols.CheckSafeLevel(fixnumCast.Context, 4, "send"); // Convert the parameters SocketFlags socketFlags = ConvertToSocketFlag(fixnumCast, flags); // Unpack the socket address information from the to parameter SocketAddress address = new SocketAddress(AddressFamily.InterNetwork); for (int i = 0; i < to.GetByteCount(); i++) { address[i] = to.GetByte(i); } EndPoint toEndPoint = self.Socket.LocalEndPoint.Create(address); return(self.Socket.SendTo(message.ConvertToBytes(), socketFlags, toEndPoint)); }
public static object Reinitialize(ConversionStorage<int>/*!*/ conversionStorage, RubyContext/*!*/ context, BlockParam block, RubyArray/*!*/ self, [NotNull]object/*!*/ arrayOrSize) { RubyUtils.RequiresNotFrozen(context, self); IList array = Protocols.AsArray(context, arrayOrSize); if (array != null) { // block ignored return Reinitialize(self, array); } int size = Protocols.CastToFixnum(conversionStorage, context, arrayOrSize); if (block != null) { return Reinitialize(block, self, size); } else { return ReinitializeByRepeatedValue(context, self, size, null); } }
public static RubyArray GetAddressInfo( ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, RubyClass/*!*/ self, object hostNameOrAddress, object port, [DefaultParameterValue(null)]object family, [DefaultParameterValue(0)]object socktype, [DefaultParameterValue(0)]object protocol, [DefaultParameterValue(null)]object flags) { IPHostEntry entry = (hostNameOrAddress != null) ? GetHostEntry(ConvertToHostString(stringCast, hostNameOrAddress)) : MakeEntry(IPAddress.Any); int iPort = ConvertToPortNum(stringCast, fixnumCast, port); // Sadly the family, socktype, protocol and flags get passed through at best and ignored at worst, // since System.Net does not provide for them AddressFamily addrFamily = ConvertToAddressFamily(stringCast, fixnumCast, family); int socketType = Protocols.CastToFixnum(fixnumCast, socktype); int protocolType = Protocols.CastToFixnum(fixnumCast, protocol); RubyArray results = new RubyArray(entry.AddressList.Length); for (int i = 0; i < entry.AddressList.Length; ++i) { IPAddress address = entry.AddressList[i]; RubyArray result = new RubyArray(9); result.Add(ToAddressFamilyString(address.AddressFamily)); result.Add(iPort); if (DoNotReverseLookup(self.Context).Value) { result.Add(MutableString.CreateAscii(address.ToString())); } else { IPHostEntry alias = GetHostEntry(address); // TODO (encoding): result.Add(MutableString.Create(alias.HostName, RubyEncoding.UTF8)); } result.Add(MutableString.CreateAscii(address.ToString())); result.Add((int)address.AddressFamily); result.Add(socketType); // TODO: protocol type: result.Add(protocolType); results.Add(result); } return results; }