Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f84808262285
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ad6e096ee6b3
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Apr 27, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6ffce7a View commit details
  2. Copy the full SHA
    258b2bd View commit details
  3. Copy the full SHA
    ad6e096 View commit details
206 changes: 111 additions & 95 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -4331,101 +4331,6 @@ public IRubyObject start_with_p(ThreadContext context, IRubyObject arg) {
}
}

@JRubyMethod(name = "delete_prefix")
public IRubyObject delete_prefix(ThreadContext context, IRubyObject prefix) {
int prefixlen;

prefixlen = deletedPrefixLength(prefix);
if (prefixlen <= 0) return strDup(context.runtime);

return makeShared(context.runtime, prefixlen, size() - prefixlen);
}

@JRubyMethod(name = "delete_suffix")
public IRubyObject delete_suffix(ThreadContext context, IRubyObject suffix) {
int suffixlen;

suffixlen = deletedSuffixLength(suffix);
if (suffixlen <= 0) return strDup(context.runtime);

return makeShared(context.runtime, 0, size() - suffixlen);
}

@JRubyMethod(name = "delete_prefix!")
public IRubyObject delete_prefix_bang(ThreadContext context, IRubyObject prefix) {
modifyAndKeepCodeRange();
int prefixlen = deletedPrefixLength(prefix);
if (prefixlen <= 0) return context.nil;

value.view(prefixlen, value.realSize() - prefixlen);
return this;
}

@JRubyMethod(name = "delete_suffix!")
public IRubyObject delete_suffix_bang(ThreadContext context, IRubyObject suffix) {
int olen, suffixlen, len;
checkFrozen();

suffixlen = deletedSuffixLength(suffix);
if (suffixlen <= 0) return context.nil;

olen = size();
modifyAndKeepCodeRange();
len = olen - suffixlen;
value.realSize(len);
if (!isCodeRangeAsciiOnly()) {
clearCodeRange();
}
return this;
}

private int deletedPrefixLength(IRubyObject _prefix) {
int strptr, prefixptr;
int olen, prefixlen;

RubyString prefix = _prefix.convertToString();
if (prefix.isBrokenString()) return 0;
checkEncoding(prefix);

/* return 0 if not start with prefix */
prefixlen = prefix.size();
if (prefixlen <= 0) return 0;
olen = size();
if (olen < prefixlen) return 0;
byte[] strBytes = value.unsafeBytes();
strptr = value.begin();
byte[] prefixBytes = prefix.value.unsafeBytes();
prefixptr = prefix.value.begin();
if (ByteList.memcmp(strBytes, strptr, prefixBytes, prefixptr, prefixlen) != 0) return 0;

return prefixlen;
}

private int deletedSuffixLength(IRubyObject _suffix) {
int strptr, suffixptr, s;
int olen, suffixlen;
Encoding enc;

RubyString suffix = _suffix.convertToString();
if (suffix.isBrokenString()) return 0;
enc = checkEncoding(suffix);

/* return 0 if not start with suffix */
suffixlen = suffix.size();
if (suffixlen <= 0) return 0;
olen = size();
if (olen < suffixlen) return 0;
byte[] strBytes = value.unsafeBytes();
strptr = value.begin();
byte[] suffixBytes = suffix.value.unsafeBytes();
suffixptr = suffix.value.begin();
s = strptr + olen - suffixlen;
if (ByteList.memcmp(strBytes, s, suffixBytes, suffixptr, suffixlen) != 0) return 0;
if (enc.leftAdjustCharHead(strBytes, strptr, s, strptr + olen) != s) return 0;

return suffixlen;
}

@JRubyMethod(name = "start_with?", rest = true)
public IRubyObject start_with_p(ThreadContext context, IRubyObject[]args) {
for (int i = 0; i < args.length; i++) {
@@ -4499,6 +4404,117 @@ public boolean endsWithAsciiChar(char c) {
return value.getEncoding().isAsciiCompatible() && (size = value.realSize()) > 0 && value.get(size - 1) == c;
}

@JRubyMethod(name = "delete_prefix")
public IRubyObject delete_prefix(ThreadContext context, IRubyObject prefix) {
int prefixlen = deletedPrefixLength(prefix);

if (prefixlen <= 0) return strDup(context.runtime);

return makeShared(context.runtime, prefixlen, size() - prefixlen);
}

@JRubyMethod(name = "delete_suffix")
public IRubyObject delete_suffix(ThreadContext context, IRubyObject suffix) {
int suffixlen = deletedSuffixLength(suffix);

if (suffixlen <= 0) return strDup(context.runtime);

return makeShared(context.runtime, 0, size() - suffixlen);
}

@JRubyMethod(name = "delete_prefix!")
public IRubyObject delete_prefix_bang(ThreadContext context, IRubyObject prefix) {
modifyAndKeepCodeRange();

int prefixlen = deletedPrefixLength(prefix);

if (prefixlen <= 0) return context.nil;

// MRI: rb_str_drop_bytes, in a nutshell
modify();
value.view(prefixlen, value.realSize() - prefixlen);
clearCodeRange();

return this;
}

@JRubyMethod(name = "delete_suffix!")
public IRubyObject delete_suffix_bang(ThreadContext context, IRubyObject suffix) {
checkFrozen();

int suffixlen = deletedSuffixLength(suffix);

if (suffixlen <= 0) return context.nil;

int olen = size();

modifyAndKeepCodeRange();

int len = olen - suffixlen;

value.realSize(len);

if (!isCodeRangeAsciiOnly()) {
clearCodeRange();
}

return this;
}

private int deletedPrefixLength(IRubyObject _prefix) {
RubyString prefix = _prefix.convertToString();

if (prefix.isBrokenString()) return 0;

checkEncoding(prefix);

/* return 0 if not start with prefix */
int prefixlen = prefix.size();

if (prefixlen <= 0) return 0;

int olen = size();

if (olen < prefixlen) return 0;

byte[] strBytes = value.unsafeBytes();
int strptr = value.begin();
byte[] prefixBytes = prefix.value.unsafeBytes();
int prefixptr = prefix.value.begin();

if (ByteList.memcmp(strBytes, strptr, prefixBytes, prefixptr, prefixlen) != 0) return 0;

return prefixlen;
}

private int deletedSuffixLength(IRubyObject _suffix) {
RubyString suffix = _suffix.convertToString();

if (suffix.isBrokenString()) return 0;

Encoding enc = checkEncoding(suffix);

/* return 0 if not start with suffix */
int suffixlen = suffix.size();

if (suffixlen <= 0) return 0;

int olen = size();

if (olen < suffixlen) return 0;
byte[] strBytes = value.unsafeBytes();
int strptr = value.begin();
byte[] suffixBytes = suffix.value.unsafeBytes();
int suffixptr = suffix.value.begin();
int s = strptr + olen - suffixlen;

if (ByteList.memcmp(strBytes, s, suffixBytes, suffixptr, suffixlen) != 0) return 0;

if (enc.leftAdjustCharHead(strBytes, strptr, s, strptr + olen) != s) return 0;

return suffixlen;
}

private static final ByteList SPACE_BYTELIST = RubyInteger.singleCharByteList((byte) ' ');

private IRubyObject justify(Ruby runtime, IRubyObject arg0, int jflag) {
8 changes: 0 additions & 8 deletions test/jruby/test_method.rb
Original file line number Diff line number Diff line change
@@ -8,14 +8,6 @@ def test_jruby_3491
end
end

def test_function_break
obj = Object.new
def obj.broken_method
break # TODO this is a SyntaxError at parse time on MRI 2.5
end
assert_raise(SyntaxError){ obj.broken_method }
end

module Methods
def self.req2(a1, a2); a1 || a2 end
def self.opt1(a1, a2 = {}); a1 if a2 end
1 change: 1 addition & 0 deletions test/mri/excludes/TestMethod.rb
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
exclude :test_orphan_callee, "needs investigation"
exclude :test_prepended_public_zsuper, "2.4 fix/change to prepend + method + super_method (#4687)"
exclude :test_splat_long_array, "passes locally but fails on travis OOME"
exclude :test_super_method_module, "needs investigation, new in 2.5"
exclude :test_super_method_removed, "finds super method when super method has been undef (#2155)"
exclude :test_super_method_with_prepended_module, "2.5 test for super with prepend has issues (#4687)"
exclude :test_to_proc_binding, "NullPointerException in parser"
1 change: 1 addition & 0 deletions test/mri/excludes/TestNetHTTP_v1_2_chunked.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude :test_get__crlf, "needs investigation, new in 2.5"
2 changes: 2 additions & 0 deletions test/mri/excludes/TestTranscode.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
exclude :test_gb18030, "perhaps a bug in pack wrt encoded text"
exclude :test_ill_formed_utf_8_replace, "needs investigation, new in 2.5"
exclude :test_invalid_replace_string, "Unicode update? #4731"
exclude :test_scrub_encode_with_coderange, "needs investigation, new in 2.5"
exclude :test_to_cp50221, "needs investigation"
exclude :test_unicode_public_review_issue_121, "broken via charset replacement"
exclude :test_utf8_mac, "needs investigation"