| Method from org.jruby.RubyMatchData Detail: |
final int backrefNumber(IRubyObject obj) {
if (obj instanceof RubySymbol) {
return nameToBackrefNumber((RubyString)((RubySymbol)obj).id2name());
} else if (obj instanceof RubyString) {
return nameToBackrefNumber((RubyString)obj);
} else {
return RubyNumeric.num2int(obj);
}
}
|
public IRubyObject begin(IRubyObject index) {
int i = backrefNumber(index);
if (regs == null) {
if (i != 0) throw getRuntime().newIndexError("index " + i + " out of matches");
if (begin < 0) return getRuntime().getNil();
return RubyFixnum.newFixnum(getRuntime(), begin);
} else {
if (i < 0 || regs.numRegs < = i) throw getRuntime().newIndexError("index " + i + " out of matches");
if (regs.beg[i] < 0) return getRuntime().getNil();
return RubyFixnum.newFixnum(getRuntime(), regs.beg[i]);
}
}
|
public IRubyObject captures(ThreadContext context) {
return match_array(context.getRuntime(), 1);
}
|
public static RubyClass createMatchDataClass(Ruby runtime) {
// TODO: Is NOT_ALLOCATABLE_ALLOCATOR ok here, since you can't actually instantiate MatchData directly?
RubyClass matchDataClass = runtime.defineClass("MatchData", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
runtime.setMatchData(matchDataClass);
runtime.defineGlobalConstant("MatchingData", matchDataClass);
matchDataClass.kindOf = new RubyModule.KindOf() {
public boolean isKindOf(IRubyObject obj, RubyModule type) {
return obj instanceof RubyMatchData;
}
};
matchDataClass.getMetaClass().undefineMethod("new");
matchDataClass.defineAnnotatedMethods(RubyMatchData.class);
return matchDataClass;
}
|
public IRubyObject end(IRubyObject index) {
int i = backrefNumber(index);
if (regs == null) {
if (i != 0) throw getRuntime().newIndexError("index " + i + " out of matches");
if (end < 0) return getRuntime().getNil();
return RubyFixnum.newFixnum(getRuntime(), end);
} else {
if (i < 0 || regs.numRegs < = i) throw getRuntime().newIndexError("index " + i + " out of matches");
if (regs.end[i] < 0) return getRuntime().getNil();
return RubyFixnum.newFixnum(getRuntime(), regs.end[i]);
}
}
|
public IRubyObject group(long n) {
return RubyRegexp.nth_match((int)n, this);
}
|
public IRubyObject group(int n) {
return RubyRegexp.nth_match(n, this);
}
|
public IRubyObject initialize_copy(IRubyObject original) {
if (this == original) return this;
if (!(getMetaClass() == original.getMetaClass())){ // MRI also does a pointer comparison here
throw getRuntime().newTypeError("wrong argument class");
}
RubyMatchData origMatchData = (RubyMatchData)original;
str = origMatchData.str;
regs = origMatchData.regs;
return this;
}
|
public IRubyObject inspect() {
if (pattern == null) return anyToString();
RubyString result = getRuntime().newString();
result.cat((byte)'#").cat((byte)'< ");
result.append(getMetaClass().getRealClass().to_s());
NameEntry[]names = new NameEntry[regs == null ? 1 : regs.numRegs];
if (pattern.numberOfNames() > 0) {
for (Iterator< NameEntry > i = pattern.namedBackrefIterator(); i.hasNext();) {
NameEntry e = i.next();
for (int num : e.getBackRefs()) names[num] = e;
}
}
for (int i=0; i< names.length; i++) {
result.cat((byte)' ");
if (i > 0) {
NameEntry e = names[i];
if (e != null) {
result.cat(e.name, e.nameP, e.nameEnd - e.nameP);
} else {
result.cat((byte)('0" + i));
}
result.cat((byte)':");
}
IRubyObject v = RubyRegexp.nth_match(i, this);
if (v.isNil()) {
result.cat("nil".getBytes());
} else {
result.append(v.inspect());
}
}
return result.cat((byte)' >");
}
|
public IRubyObject offset(IRubyObject index) {
int i = backrefNumber(index);
Ruby runtime = getRuntime();
if (regs == null) {
if (i != 0) throw getRuntime().newIndexError("index " + i + " out of matches");
if (begin < 0) return runtime.newArray(runtime.getNil(), runtime.getNil());
return runtime.newArray(RubyFixnum.newFixnum(runtime, begin),RubyFixnum.newFixnum(runtime, end));
} else {
if (i < 0 || regs.numRegs < = i) throw runtime.newIndexError("index " + i + " out of matches");
if (regs.beg[i] < 0) return runtime.newArray(runtime.getNil(), runtime.getNil());
return runtime.newArray(RubyFixnum.newFixnum(runtime, regs.beg[i]),RubyFixnum.newFixnum(runtime, regs.end[i]));
}
}
|
public IRubyObject op_aref(IRubyObject[] args) {
switch (args.length) {
case 1:
return op_aref(args[0]);
case 2:
return op_aref(args[0], args[1]);
default:
Arity.raiseArgumentError(getRuntime(), args.length, 1, 2);
return null; // not reached
}
} Deprecated! Use - the versions with zero, one, or two args.
Variable arity version for compatibility. Not bound to a Ruby method. |
public IRubyObject op_aref(IRubyObject idx) {
IRubyObject result = op_arefCommon(idx);
return result == null ? ((RubyArray)to_a()).aref(idx) : result;
}
|
public IRubyObject op_aref(IRubyObject idx,
IRubyObject rest) {
IRubyObject result;
return !rest.isNil() || (result = op_arefCommon(idx)) == null ? ((RubyArray)to_a()).aref(idx, rest) : result;
}
|
public IRubyObject post_match(ThreadContext context) {
RubyString ss;
if (regs == null) {
if (begin == -1) return context.getRuntime().getNil();
ss = str.makeShared(context.getRuntime(), end, str.getByteList().length() - end);
} else {
if (regs.beg[0] == -1) return context.getRuntime().getNil();
ss = str.makeShared(context.getRuntime(), regs.end[0], str.getByteList().length() - regs.end[0]);
}
if(isTaint()) ss.setTaint(true);
return ss;
}
|
public IRubyObject pre_match(ThreadContext context) {
RubyString ss;
if (regs == null) {
if(begin == -1) return context.getRuntime().getNil();
ss = str.makeShared(context.getRuntime(), 0, begin);
} else {
if(regs.beg[0] == -1) return context.getRuntime().getNil();
ss = str.makeShared(context.getRuntime(), 0, regs.beg[0]);
}
if (isTaint()) ss.setTaint(true);
return ss;
}
|
public IRubyObject select(ThreadContext context,
Block block) {
return block.yield(context, to_a());
}
|
public IRubyObject size() {
return regs == null ? RubyFixnum.one(getRuntime()) : RubyFixnum.newFixnum(getRuntime(), regs.numRegs);
}
|
public IRubyObject string() {
return str; //str is frozen
}
|
public RubyArray to_a() {
return match_array(getRuntime(), 0);
}
|
public IRubyObject to_s() {
IRubyObject ss = RubyRegexp.last_match(this);
if (ss.isNil()) ss = RubyString.newEmptyString(getRuntime());
if (isTaint()) ss.setTaint(true);
return ss;
}
|
public final void use() {
// rb_match_busy
flags |= MATCH_BUSY;
}
|
public final boolean used() {
return (flags & MATCH_BUSY) != 0;
}
|
public IRubyObject values_at(IRubyObject[] args) {
return to_a().values_at(args);
}
|