Skip to content

Commit

Permalink
[Truffle] - String#capitalize(!) should preserve the string encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasallan committed Dec 22, 2014
1 parent c1f0e4c commit 86cab8d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,10 @@ public RubyString capitalizeBang(RubyString string) {
} else {
String head = javaString.substring(0, 1).toUpperCase();
String tail = javaString.substring(1, javaString.length()).toLowerCase();
string.set(ByteList.create((head + tail)));
ByteList byteListString = ByteList.create(head + tail);
byteListString.setEncoding(string.getBytes().getEncoding());

string.set(byteListString);
return string;
}
}
Expand All @@ -1243,7 +1246,10 @@ public RubyString capitalize(RubyString string) {
} else {
String head = javaString.substring(0, 1).toUpperCase();
String tail = javaString.substring(1, javaString.length()).toLowerCase();
return string.getContext().makeString(head + tail);
ByteList byteListString = ByteList.create(head + tail);
byteListString.setEncoding(string.getBytes().getEncoding());

return string.getContext().makeString(byteListString);
}
}

Expand Down

0 comments on commit 86cab8d

Please sign in to comment.