Skip to content

Commit

Permalink
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -5250,11 +5250,30 @@ public IRubyObject start_with_p(ThreadContext context, IRubyObject[]args) {
}

private boolean start_with_pCommon(IRubyObject arg) {
IRubyObject tmp = arg.checkStringType();
if (tmp.isNil()) return false;
RubyString otherString = (RubyString)tmp;
Ruby runtime = getRuntime();
RubyString otherString;

if (!runtime.is2_0()) {
// 1.8 and 1.9 ignores uncoercible argument
IRubyObject tmp = arg.checkStringType();
if (tmp.isNil()) return false;
otherString = (RubyString) tmp;
} else {
// 2.0+ requires coersion to succeed
otherString = arg.convertToString();
}

checkEncoding(otherString);

int otherLength = otherString.value.getRealSize();

if (otherLength == 0) {
// other is '', so return true
return true;
}

if (value.getRealSize() < otherString.value.getRealSize()) return false;

return value.startsWith(otherString.value);
}

0 comments on commit d7db423

Please sign in to comment.