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: 34b5582c6a6e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 349f57ba8ec5
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 20, 2015

  1. 2
    Copy the full SHA
    6101605 View commit details
  2. Copy the full SHA
    349f57b View commit details
Showing with 29 additions and 25 deletions.
  1. +13 −8 core/src/main/java/org/jruby/RubyString.java
  2. +16 −17 core/src/main/java/org/jruby/util/StringSupport.java
21 changes: 13 additions & 8 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -4101,12 +4101,17 @@ public IRubyObject chop19(ThreadContext context) {

@JRubyMethod(name = "chop!")
public IRubyObject chop_bang19(ThreadContext context) {
modifyCheck();
Ruby runtime = context.runtime;
if (value.getRealSize() == 0) return runtime.getNil();
view(0, StringSupport.choppedLength19(this, runtime));
if (getCodeRange() != CR_7BIT) clearCodeRange();
return this;
modifyAndKeepCodeRange();
if (size() > 0) {
int len;
len = StringSupport.choppedLength19(this, context.runtime);
value.realSize(len);
if (getCodeRange() != CR_7BIT) {
clearCodeRange();
}
return this;
}
return context.nil;
}

public RubyString chomp(ThreadContext context) {
@@ -5626,10 +5631,10 @@ public IRubyObject encode(ThreadContext context, IRubyObject toEncoding,

@JRubyMethod
public IRubyObject force_encoding(ThreadContext context, IRubyObject enc) {
return force_encoding(context, context.runtime.getEncodingService().getEncodingFromObject(enc));
return force_encoding(EncodingUtils.rbToEncoding(context, enc));
}

private IRubyObject force_encoding(ThreadContext context, Encoding encoding) {
private IRubyObject force_encoding(Encoding encoding) {
modify19();
associateEncoding(encoding);
clearCodeRange();
33 changes: 16 additions & 17 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -1405,24 +1405,23 @@ public static CodeRangeable delete_bangCommon19(CodeRangeable rubyString, Ruby r
}

/**
* rb_str_chop
* MRI: chopped_length
*/
public static int choppedLength19(CodeRangeable rubyString, Ruby runtime) {
final ByteList value = rubyString.getByteList();
int p = value.getBegin();
int end = p + value.getRealSize();

if (p > end) return 0;
byte bytes[] = value.getUnsafeBytes();
Encoding enc = value.getEncoding();

int s = enc.prevCharHead(bytes, p, end, end);
if (s == -1) return 0;
if (s > p && codePoint(runtime, enc, bytes, s, end) == '\n') {
int s2 = enc.prevCharHead(bytes, p, s, end);
if (s2 != -1 && codePoint(runtime, enc, bytes, s2, end) == '\r') s = s2;
}
return s - p;
public static int choppedLength19(CodeRangeable str, Ruby runtime) {
ByteList bl = str.getByteList();
Encoding enc = bl.getEncoding();
int p, p2, beg, end;

beg = bl.begin();
end = beg + bl.realSize();
if (beg > end) return 0;
p = enc.prevCharHead(bl.unsafeBytes(), beg, end, end);
if (p == 0) return 0;
if (p > beg && EncodingUtils.encAscget(bl.unsafeBytes(), p, end, null, enc) == '\n') {
p2 = enc.prevCharHead(bl.unsafeBytes(), beg, p, end);
if (p2 != 0 && EncodingUtils.encAscget(bl.unsafeBytes(), p2, end, null, enc) == '\r') p = p2;
}
return p - beg;
}

/**