Skip to content

Commit

Permalink
Additional minor tweaks for JRUBY-6434
Browse files Browse the repository at this point in the history
* Propagate format string's encoding into key names
* Eliminate useless Ruby-land sprintf def
* Eliminate deprecated call from RubyKernel.printf

Conflicts:

	src/jruby/kernel19/kernel.rb
  • Loading branch information
headius committed Feb 13, 2012
1 parent 1d84a5a commit 0d79417
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/org/jruby/RubyKernel.java
Expand Up @@ -528,7 +528,7 @@ public static IRubyObject printf(ThreadContext context, IRubyObject recv, IRubyO
args = ArgsUtil.popArray(args);
}

defout.callMethod(context, "write", RubyKernel.sprintf(recv, args));
defout.callMethod(context, "write", RubyKernel.sprintf(context, recv, args));
}

return context.getRuntime().getNil();
Expand Down
12 changes: 8 additions & 4 deletions src/org/jruby/util/Sprintf.java
Expand Up @@ -32,6 +32,8 @@
import java.text.NumberFormat;
import java.util.Locale;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyBignum;
Expand Down Expand Up @@ -246,6 +248,7 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat
int start;
int mark;
ByteList name = null;
Encoding encoding = null;

if (charFormat instanceof ByteList) {
ByteList list = (ByteList)charFormat;
Expand All @@ -255,12 +258,14 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat
length = begin + list.length();
start = begin;
mark = begin;
encoding = list.getEncoding();
} else {
format = stringToBytes(charFormat, false);
offset = 0;
length = charFormat.length();
start = 0;
mark = 0;
mark = 0;
encoding = UTF8Encoding.INSTANCE;
}

while (offset < length) {
Expand Down Expand Up @@ -314,8 +319,7 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat

if (nameEnd == nameStart) raiseArgumentError(args, ERR_MALFORMED_NAME);

// TODO: encoding for name?
name = new ByteList(format, nameStart, nameEnd - nameStart);
name = new ByteList(format, nameStart, nameEnd - nameStart, encoding, false);

break;
}
Expand All @@ -335,7 +339,7 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat

if (nameEnd == nameStart) raiseArgumentError(args, ERR_MALFORMED_NAME);

ByteList localName = new ByteList(format, nameStart, nameEnd - nameStart);
ByteList localName = new ByteList(format, nameStart, nameEnd - nameStart, encoding, false);
buf.append(args.next(localName).asString().getByteList());
incomplete = false;

Expand Down

0 comments on commit 0d79417

Please sign in to comment.