static IRubyObject parse(ThreadContext context, IRubyObject string, String format) { string = TypeConverter.checkStringType(context.runtime, string); return new RubyDateParser().parse(context, format, (RubyString) string); }
static IRubyObject parse(ThreadContext context, IRubyObject string, String format) { string = TypeConverter.checkStringType(context.runtime, string); return new RubyDateParser().parse(context, format, (RubyString) string); }
@JRubyMethod(meta = true) public static IRubyObject _strptime(ThreadContext context, IRubyObject self, IRubyObject string, IRubyObject format) { format = TypeConverter.checkStringType(context.runtime, format); return parse(context, string, ((RubyString) format).decodeString()); }
@JRubyMethod(meta = true) public static IRubyObject _strptime(ThreadContext context, IRubyObject self, IRubyObject string, IRubyObject format) { format = TypeConverter.checkStringType(context.runtime, format); return parse(context, string, ((RubyString) format).decodeString()); }
/** rb_check_string_type * * Tries to return a coerced string representation of this object, * using "to_str". If that returns something other than a String * or nil, an empty String will be returned. * */ @Override public IRubyObject checkStringType() { Ruby runtime = getRuntime(); ThreadContext context = runtime.getCurrentContext(); BasicObjectSites sites = sites(context); return TypeConverter.checkStringType(context, sites.to_str_checked, this); }
/** rb_check_string_type * * Tries to return a coerced string representation of this object, * using "to_str". If that returns something other than a String * or nil, an empty String will be returned. * */ @Override public IRubyObject checkStringType() { Ruby runtime = getRuntime(); ThreadContext context = runtime.getCurrentContext(); BasicObjectSites sites = sites(context); return TypeConverter.checkStringType(context, sites.to_str_checked, this); }
static Sock sockFromArg(IRubyObject type) { IRubyObject maybeString = TypeConverter.checkStringType(type.getRuntime(), type); if (!maybeString.isNil()) { type = maybeString; } try { if(type instanceof RubyString || type instanceof RubySymbol) { String typeString = type.toString(); if (typeString.startsWith("SOCK_")) return Sock.valueOf(typeString.toString()); return Sock.valueOf("SOCK_" + typeString); } int typeInt = RubyNumeric.fix2int(type); return Sock.valueOf(typeInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(type.getRuntime(), "invalid socket type: " + type); } }
static SocketOption optionFromArg(IRubyObject opt) { IRubyObject maybeString = TypeConverter.checkStringType(opt.getRuntime(), opt); if (!maybeString.isNil()) { opt = maybeString; } try { if (opt instanceof RubyString || opt instanceof RubySymbol) { String optString = opt.toString(); if (optString.startsWith("SO_")) return SocketOption.valueOf(optString); return SocketOption.valueOf("SO_" + optString); } return SocketOption.valueOf(RubyNumeric.fix2int(opt)); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(opt.getRuntime(), "invalid socket option: " + opt); } }
static SocketLevel levelFromArg(IRubyObject level) { IRubyObject maybeString = TypeConverter.checkStringType(level.getRuntime(), level); if (!maybeString.isNil()) { level = maybeString; } try { if (level instanceof RubyString || level instanceof RubySymbol) { String levelString = level.toString(); if(levelString.startsWith("SOL_")) return SocketLevel.valueOf(levelString); return SocketLevel.valueOf("SOL_" + levelString); } return SocketLevel.valueOf(RubyNumeric.fix2int(level)); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(level.getRuntime(), "invalid socket level: " + level); } }
static SocketOption optionFromArg(IRubyObject opt) { IRubyObject maybeString = TypeConverter.checkStringType(opt.getRuntime(), opt); if (!maybeString.isNil()) { opt = maybeString; } try { if (opt instanceof RubyString || opt instanceof RubySymbol) { String optString = opt.toString(); if (optString.startsWith("SO_")) return SocketOption.valueOf(optString); return SocketOption.valueOf("SO_" + optString); } return SocketOption.valueOf(RubyNumeric.fix2int(opt)); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(opt.getRuntime(), "invalid socket option: " + opt); } }
static SocketLevel levelFromArg(IRubyObject level) { IRubyObject maybeString = TypeConverter.checkStringType(level.getRuntime(), level); if (!maybeString.isNil()) { level = maybeString; } try { if (level instanceof RubyString || level instanceof RubySymbol) { String levelString = level.toString(); if(levelString.startsWith("SOL_")) return SocketLevel.valueOf(levelString); return SocketLevel.valueOf("SOL_" + levelString); } return SocketLevel.valueOf(RubyNumeric.fix2int(level)); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(level.getRuntime(), "invalid socket level: " + level); } }
@JRubyMethod(name = "String", required = 1, module = true, visibility = PRIVATE) public static IRubyObject new_string(ThreadContext context, IRubyObject recv, IRubyObject object) { Ruby runtime = context.runtime; KernelSites sites = sites(context); IRubyObject tmp = TypeConverter.checkStringType(context, sites.to_str_checked, object, runtime.getString()); if (tmp == context.nil) { tmp = TypeConverter.convertToType(context, object, runtime.getString(), sites(context).to_s_checked); } return tmp; }
static Protocol protocolFromArg(IRubyObject protocol) { IRubyObject maybeString = TypeConverter.checkStringType(protocol.getRuntime(), protocol); if (!maybeString.isNil()) { protocol = maybeString; } try { if(protocol instanceof RubyString || protocol instanceof RubySymbol) { String protocolString = protocol.toString(); return Protocol.getProtocolByName(protocolString); } int protocolInt = RubyNumeric.fix2int(protocol); return Protocol.getProtocolByNumber(protocolInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(protocol.getRuntime(), "invalid protocol: " + protocol); } }
static Protocol protocolFromArg(IRubyObject protocol) { IRubyObject maybeString = TypeConverter.checkStringType(protocol.getRuntime(), protocol); if (!maybeString.isNil()) { protocol = maybeString; } try { if(protocol instanceof RubyString || protocol instanceof RubySymbol) { String protocolString = protocol.toString(); return Protocol.getProtocolByName(protocolString); } int protocolInt = RubyNumeric.fix2int(protocol); return Protocol.getProtocolByNumber(protocolInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(protocol.getRuntime(), "invalid protocol: " + protocol); } }
static ProtocolFamily protocolFamilyFromArg(IRubyObject protocol) { IRubyObject maybeString = TypeConverter.checkStringType(protocol.getRuntime(), protocol); if (!maybeString.isNil()) { protocol = maybeString; } try { if (protocol instanceof RubyString || protocol instanceof RubySymbol) { String protocolString = protocol.toString(); if (protocolString.startsWith("PF_")) return ProtocolFamily.valueOf(protocolString); if (protocolString.startsWith("AF_")) return ProtocolFamily.valueOf(AddressFamily.valueOf(protocolString).intValue()); return ProtocolFamily.valueOf("PF_" + protocolString); } int protocolInt = RubyNumeric.fix2int(protocol); return ProtocolFamily.valueOf(protocolInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(protocol.getRuntime(), "invalid protocol family: " + protocol); } }
@JRubyMethod(name = "String", required = 1, module = true, visibility = PRIVATE) public static IRubyObject new_string(ThreadContext context, IRubyObject recv, IRubyObject object) { Ruby runtime = context.runtime; KernelSites sites = sites(context); IRubyObject tmp = TypeConverter.checkStringType(context, sites.to_str_checked, object, runtime.getString()); if (tmp == context.nil) { tmp = TypeConverter.convertToType(context, object, runtime.getString(), sites(context).to_s_checked); } return tmp; }
public static int portToInt(IRubyObject port) { if (port.isNil()) return 0; Ruby runtime = port.getRuntime(); IRubyObject maybeStr = TypeConverter.checkStringType(runtime, port); if (!maybeStr.isNil()) { RubyString portStr = maybeStr.convertToString(); jnr.netdb.Service serv = jnr.netdb.Service.getServiceByName(portStr.toString(), null); if (serv != null) return serv.getPort(); return RubyNumeric.fix2int(portStr.to_i()); } return RubyNumeric.fix2int(port); } }
@JRubyMethod(name = "<=>") @Override public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyString) { return runtime.newFixnum(op_cmp((RubyString)other)); } JavaSites.CheckedSites sites = sites(context).to_str_checked; if (sites.respond_to_X.respondsTo(context, this, other)) { IRubyObject tmp = TypeConverter.checkStringType(context, sites, other); if (tmp instanceof RubyString) return runtime.newFixnum(op_cmp((RubyString) tmp)); } else { return invcmp(context, sites(context).recursive_cmp, this, other); } return context.nil; }
public static int portToInt(IRubyObject port) { if (port.isNil()) return 0; Ruby runtime = port.getRuntime(); IRubyObject maybeStr = TypeConverter.checkStringType(runtime, port); if (!maybeStr.isNil()) { RubyString portStr = maybeStr.convertToString(); jnr.netdb.Service serv = jnr.netdb.Service.getServiceByName(portStr.toString(), null); if (serv != null) return serv.getPort(); return RubyNumeric.fix2int(portStr.to_i()); } return RubyNumeric.fix2int(port); } }
@JRubyMethod(name = "<=>") @Override public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (other instanceof RubyString) { return runtime.newFixnum(op_cmp((RubyString)other)); } JavaSites.CheckedSites sites = sites(context).to_str_checked; if (sites.respond_to_X.respondsTo(context, this, other)) { IRubyObject tmp = TypeConverter.checkStringType(context, sites, other); if (tmp instanceof RubyString) return runtime.newFixnum(op_cmp((RubyString) tmp)); } else { return invcmp(context, sites(context).recursive_cmp, this, other); } return context.nil; }