/** rb_reg_initialize_m
*/
@JRubyMethod(name = "initialize", optional = 3, visibility = Visibility.PRIVATE)
public IRubyObject initialize_m(IRubyObject[] args) {
ByteList bytes;
int regexFlags = 0;
if (args[0] instanceof RubyRegexp) {
if (args.length > 1) {
getRuntime().getWarnings().warn(ID.REGEXP_IGNORED_FLAGS, "flags" + (args.length == 3 ? " and encoding" : "") + " ignored");
}
RubyRegexp regexp = (RubyRegexp)args[0];
regexp.check();
regexFlags = (int)regexp.pattern.getOptions() & 0xF;
if (!regexp.isKCodeDefault() && regexp.kcode != null && regexp.kcode != KCode.NIL) {
if (regexp.kcode == KCode.NONE) {
regexFlags |= 16;
} else if (regexp.kcode == KCode.EUC) {
regexFlags |= 32;
} else if (regexp.kcode == KCode.SJIS) {
regexFlags |= 48;
} else if (regexp.kcode == KCode.UTF8) {
regexFlags |= 64;
}
}
bytes = regexp.str;
} else {
if (args.length >= 2) {
if (args[1] instanceof RubyFixnum) {
regexFlags = RubyNumeric.fix2int(args[1]);
} else if (args[1].isTrue()) {
regexFlags = RE_OPTION_IGNORECASE;
}
}
if (args.length == 3 && !args[2].isNil()) {
ByteList kcodeBytes = args[2].convertToString().getByteList();
char first = kcodeBytes.length() > 0 ? kcodeBytes.charAt(0) : 0;
regexFlags &= ~0x70;
switch (first) {
case 'n': case 'N':
regexFlags |= 16;
break;