Skip to content

Commit

Permalink
[Truffle] String#% now uses the encoding of the format string.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Jan 14, 2015
1 parent 85f99ff commit 0fb7e04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ private RubyString formatSlow(RubyString format, Object[] args) {

if (args.length == 1 && args[0] instanceof RubyArray) {
singleArrayProfile.enter();
return context.makeString(StringFormatter.format(getContext(), format.toString(), Arrays.asList(((RubyArray) args[0]).slowToArray())));
return context.makeString(StringFormatter.format(getContext(), format.toString(), Arrays.asList(((RubyArray) args[0]).slowToArray())), format.getByteList().getEncoding());
} else {
multipleArgumentsProfile.enter();
return context.makeString(StringFormatter.format(getContext(), format.toString(), Arrays.asList(args)));
return context.makeString(StringFormatter.format(getContext(), format.toString(), Arrays.asList(args)), format.getByteList().getEncoding());
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ public RubyString makeString(String string) {
return RubyString.fromJavaString(coreLibrary.getStringClass(), string);
}

public RubyString makeString(String string, Encoding encoding) {
return RubyString.fromJavaString(coreLibrary.getStringClass(), string, encoding);
}

public RubyString makeString(char string) {
return makeString(Character.toString(string));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public static RubyString fromJavaString(RubyClass stringClass, String string) {
return new RubyString(stringClass, new ByteList(org.jruby.RubyEncoding.encodeUTF8(string), USASCIIEncoding.INSTANCE, false));
}

public static RubyString fromJavaString(RubyClass stringClass, String string, Encoding encoding) {
return new RubyString(stringClass, new ByteList(org.jruby.RubyEncoding.encodeUTF8(string), encoding, false));
}

public static RubyString fromByteList(RubyClass stringClass, ByteList bytes) {
return new RubyString(stringClass, bytes);
}
Expand Down

0 comments on commit 0fb7e04

Please sign in to comment.