Skip to content
Permalink
Browse files
[Truffle] - String#capitalize(!) should preserve the string encoding
  • Loading branch information
lucasallan committed Dec 22, 2014
1 parent c1f0e4c commit 86cab8d4c6805c995e72b03a400e4dc7a9d46690
Showing with 8 additions and 2 deletions.
  1. +8 −2 core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
@@ -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;
}
}
@@ -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);
}
}

0 comments on commit 86cab8d

Please sign in to comment.