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

Commits on Mar 23, 2015

  1. Copy the full SHA
    cf1c6b1 View commit details
  2. Copy the full SHA
    0f3475f View commit details
Showing with 23 additions and 10 deletions.
  1. +16 −8 core/src/main/java/org/jruby/RubyString.java
  2. +4 −0 core/src/main/java/org/jruby/util/Sprintf.java
  3. +3 −2 core/src/main/java/org/jruby/util/StringSupport.java
24 changes: 16 additions & 8 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -2067,22 +2067,29 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
int cc = 0;

int n = StringSupport.preciseLength(enc, bytes, p, end);
if (n <= 0) {
if (!MBCLEN_CHARFOUND_P(n)) {
if (p > prev) result.cat(bytes, prev, p - prev);
n = enc.minLength();
if (end < p + n) n = end - p;
while (n-- > 0) {
result.modifyExpand(result.size() + 4);
Sprintf.sprintf(runtime, result.getByteList() ,"\\x%02X", bytes[p] & 0377);
prev = ++p;
}
continue;
}
n = MBCLEN_CHARFOUND_LEN(n);
int c = enc.mbcToCode(bytes, p, end);
p += n;
if ((asciiCompat || isUnicode) &&
(c == '"' || c == '\\' ||
(c == '#' && p < end && (StringSupport.preciseLength(enc, bytes, p, end) > 0) &&
(cc = codePoint(runtime, enc, bytes, p, end)) == '$' || cc == '@' || cc == '{'))) {
(c == '#' &&
p < end &&
MBCLEN_CHARFOUND_P(StringSupport.preciseLength(enc, bytes, p, end)) &&
((cc = codePoint(runtime, enc, bytes, p, end)) == '$' ||
cc == '@' || cc == '{')
)
)) {
if (p - n > prev) result.cat(bytes, prev, p - n - prev);
result.cat('\\');
if (asciiCompat || enc == resultEnc) {
@@ -2111,11 +2118,12 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
continue;
}

if ((enc == resultEnc && enc.isPrint(c)) || (asciiCompat && Encoding.isAscii(c) && enc.isPrint(c))) {
// FIXME: Can't use Encoding.isAscii because it does not treat int as unsigned 32-bit
if ((enc == resultEnc && enc.isPrint(c)) || (asciiCompat && (c < 128 && c > 0) && enc.isPrint(c))) {
continue;
} else {
if (p - n > prev) result.cat(bytes, prev, p - n - prev);
Sprintf.sprintf(runtime, result.getByteList() , StringSupport.escapedCharFormat(c, isUnicode), c);
Sprintf.sprintf(runtime, result.getByteList() , StringSupport.escapedCharFormat(c, isUnicode), (c & 0xFFFFFFFFL));
prev = p;
continue;
}
@@ -2211,11 +2219,11 @@ public RubyString concat(IRubyObject other) {
public RubyString concat19(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
if (other instanceof RubyFixnum) {
int c = RubyNumeric.num2int(other);
long c = RubyNumeric.num2long(other);
if (c < 0) {
throw runtime.newRangeError("negative string size (or size too big)");
throw runtime.newRangeError("" + c + " out of char range");
}
return concatNumeric(runtime, c);
return concatNumeric(runtime, (int)(c & 0xFFFFFFFF));
} else if (other instanceof RubyBignum) {
if (((RubyBignum) other).getBigIntegerValue().signum() < 0) {
throw runtime.newRangeError("negative string size (or size too big)");
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
@@ -228,6 +228,10 @@ public static boolean sprintf(Ruby runtime, ByteList to, CharSequence format, in
return rubySprintf(to, format, new Args(runtime, (long)arg));
}

public static boolean sprintf(Ruby runtime, ByteList to, CharSequence format, long arg) {
return rubySprintf(to, format, new Args(runtime, arg));
}

public static boolean sprintf(ByteList to, RubyString format, IRubyObject args) {
return rubySprintf(to, format.getByteList(), new Args(args));
}
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -573,17 +573,18 @@ public static boolean isUnicode(Encoding enc) {

public static String escapedCharFormat(int c, boolean isUnicode) {
String format;
// c comparisons must be unsigned 32-bit
if (isUnicode) {

if (c < 0x7F && Encoding.isAscii(c) && ASCIIEncoding.INSTANCE.isPrint(c)) {
if ((c & 0xFFFFFFFFL) < 0x7F && Encoding.isAscii(c) && ASCIIEncoding.INSTANCE.isPrint(c)) {
format = "%c";
} else if (c < 0x10000) {
format = "\\u%04X";
} else {
format = "\\u{%X}";
}
} else {
if (c < 0x100) {
if ((c & 0xFFFFFFFFL) < 0x100) {
format = "\\x%02X";
} else {
format = "\\x{%X}";