private Encoding getEncodingForKCodeDefault(Ruby runtime, Regex pattern, IRubyObject pat) { Encoding enc = pattern.getEncoding(); if (enc != runtime.getKCode().getEncoding() && pat instanceof RubyRegexp) { RubyRegexp regexp = (RubyRegexp) pat; if (regexp.isKCodeDefault()) { enc = runtime.getKCode().getEncoding(); } } return enc; }
@Override public int hashCode() { int hash = 7; hash = 11 * hash + (this.kcode != null ? this.kcode.hashCode() : 0); hash = 11 * hash + (this.fixed ? 1 : 0); hash = 11 * hash + (this.once ? 1 : 0); hash = 11 * hash + (this.extended ? 1 : 0); hash = 11 * hash + (this.multiline ? 1 : 0); hash = 11 * hash + (this.ignorecase ? 1 : 0); hash = 11 * hash + (this.java ? 1 : 0); hash = 11 * hash + (this.encodingNone ? 1 : 0); hash = 11 * hash + (this.kcodeDefault ? 1 : 0); hash = 11 * hash + (this.literal ? 1 : 0); return hash; }
@Override public String toString() { return name(); } }
/** rb_reg_s_quote * */ @JRubyMethod(name = {"quote", "escape"}, required = 1, optional = 1, meta = true, compat = CompatVersion.RUBY1_8) public static RubyString quote(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; final KCode code; if (args.length == 1 || args[1].isNil()) { code = runtime.getKCode(); } else { code = KCode.create(runtime, args[1].toString()); } RubyString src = args[0].convertToString(); RubyString dst = RubyString.newStringShared(runtime, quote(src.getByteList(), code.getEncoding())); dst.infectBy(src); return dst; }
@Override public IRubyObject set(IRubyObject value) { runtime.setKCode(KCode.create(value.convertToString().toString())); return value; } }
@Override public IRubyObject get() { String kcode = runtime.getKCode().getKCode(); return kcode == null ? runtime.getNil() : runtime.newString(kcode); }
@Override public IRubyObject get() { return runtime.getKCode().kcode(runtime); }
public static RegexpOptions fromJoniOptions(int joniOptions) { KCode kcode = KCode.fromBits(joniOptions); RegexpOptions options = new RegexpOptions(kcode, kcode == KCode.NONE); options.setMultiline((joniOptions & RubyRegexp.RE_OPTION_MULTILINE) != 0); options.setIgnorecase((joniOptions & RubyRegexp.RE_OPTION_IGNORECASE) != 0); options.setExtended((joniOptions & RubyRegexp.RE_OPTION_EXTENDED) != 0); options.setFixed((joniOptions & RubyRegexp.RE_FIXED) != 0); options.setOnce((joniOptions & RubyRegexp.RE_OPTION_ONCE) != 0); return options; }
/** * This int value is meant to only be used when dealing directly with * the joni regular expression library. It differs from embeddedOptions * in that it only contains bit values which Joni cares about. */ public int toJoniOptions() { int options = 0; // Note: once is not an option that is pertinent to Joni so we exclude it. if (multiline) options |= RubyRegexp.RE_OPTION_MULTILINE; if (ignorecase) options |= RubyRegexp.RE_OPTION_IGNORECASE; if (extended) options |= RubyRegexp.RE_OPTION_EXTENDED; if (!isKcodeDefault()) options |= kcode.bits(); return options; }
/** rb_reg_s_quote * */ @JRubyMethod(name = {"quote", "escape"}, required = 1, optional = 1, meta = true, compat = CompatVersion.RUBY1_8) public static RubyString quote(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; final KCode code; if (args.length == 1 || args[1].isNil()) { code = runtime.getKCode(); } else { code = KCode.create(runtime, args[1].toString()); } RubyString src = args[0].convertToString(); RubyString dst = RubyString.newStringShared(runtime, quote(src.getByteList(), code.getEncoding())); dst.infectBy(src); return dst; }
@Override public IRubyObject set(IRubyObject value) { runtime.setKCode(KCode.create(value.convertToString().toString())); return value; } }
@Override public IRubyObject get() { String kcode = runtime.getKCode().getKCode(); return kcode == null ? runtime.getNil() : runtime.newString(kcode); }
@Override public IRubyObject get() { return runtime.getKCode().kcode(runtime); }
public static RegexpOptions fromJoniOptions(int joniOptions) { KCode kcode = KCode.fromBits(joniOptions); RegexpOptions options = new RegexpOptions(kcode, kcode == KCode.NONE); options.setMultiline((joniOptions & RubyRegexp.RE_OPTION_MULTILINE) != 0); options.setIgnorecase((joniOptions & RubyRegexp.RE_OPTION_IGNORECASE) != 0); options.setExtended((joniOptions & RubyRegexp.RE_OPTION_EXTENDED) != 0); options.setFixed((joniOptions & RubyRegexp.RE_FIXED) != 0); options.setOnce((joniOptions & RubyRegexp.RE_OPTION_ONCE) != 0); return options; }
/** * This int value is meant to only be used when dealing directly with * the joni regular expression library. It differs from embeddedOptions * in that it only contains bit values which Joni cares about. */ public int toJoniOptions() { int options = 0; // Note: once is not an option that is pertinent to Joni so we exclude it. if (multiline) options |= RubyRegexp.RE_OPTION_MULTILINE; if (ignorecase) options |= RubyRegexp.RE_OPTION_IGNORECASE; if (extended) options |= RubyRegexp.RE_OPTION_EXTENDED; if (!isKcodeDefault()) options |= kcode.bits(); return options; }
private Encoding getEncodingForKCodeDefault(Ruby runtime, Regex pattern, IRubyObject pat) { Encoding enc = pattern.getEncoding(); if (enc != runtime.getKCode().getEncoding() && pat instanceof RubyRegexp) { RubyRegexp regexp = (RubyRegexp) pat; if (regexp.isKCodeDefault()) { enc = runtime.getKCode().getEncoding(); } } return enc; }
String eArg = grabValue(getArgumentError("provide a value for -K")); config.setKCode(KCode.create(eArg)); config.setSourceEncoding(config.getKCode().getEncoding().toString()); config.setExternalEncoding(config.getKCode().getEncoding().toString());
@Override public String toString() { return name(); } }
@Override public IRubyObject set(IRubyObject value) { runtime.setKCode(KCode.create(runtime, value.convertToString().toString())); return value; } }
@Override public int hashCode() { int hash = 7; hash = 11 * hash + (this.kcode != null ? this.kcode.hashCode() : 0); hash = 11 * hash + (this.fixed ? 1 : 0); hash = 11 * hash + (this.once ? 1 : 0); hash = 11 * hash + (this.extended ? 1 : 0); hash = 11 * hash + (this.multiline ? 1 : 0); hash = 11 * hash + (this.ignorecase ? 1 : 0); hash = 11 * hash + (this.java ? 1 : 0); hash = 11 * hash + (this.encodingNone ? 1 : 0); hash = 11 * hash + (this.kcodeDefault ? 1 : 0); hash = 11 * hash + (this.literal ? 1 : 0); return hash; }