Permalink
Browse files

Merge pull request #457 from kou/support-encoding-object-for-encoding…

…-compatible-p

Accept Encoding object for Encoding.compatible?
  • Loading branch information...
2 parents 3289fed + a707f6c commit cc90601a0dccd47b559890e358c98f2629334ec1 @BanzaiMan BanzaiMan committed Jan 5, 2013
Showing with 15 additions and 3 deletions.
  1. +15 −3 src/org/jruby/RubyEncoding.java
@@ -116,10 +116,22 @@ public final Encoding getEncoding() {
}
public static Encoding areCompatible(IRubyObject obj1, IRubyObject obj2) {
- if (obj1 instanceof EncodingCapable && obj2 instanceof EncodingCapable) {
- Encoding enc1 = ((EncodingCapable)obj1).getEncoding();
- Encoding enc2 = ((EncodingCapable)obj2).getEncoding();
+ Encoding enc1 = null;
+ Encoding enc2 = null;
+ if (obj1 instanceof RubyEncoding) {
+ enc1 = ((RubyEncoding)obj1).getEncoding();
+ } else if (obj1 instanceof EncodingCapable) {
+ enc1 = ((EncodingCapable)obj1).getEncoding();
+ }
+
+ if (obj2 instanceof RubyEncoding) {
+ enc2 = ((RubyEncoding)obj2).getEncoding();
+ } else if (obj2 instanceof EncodingCapable) {
+ enc2 = ((EncodingCapable)obj2).getEncoding();
+ }
+
+ if (enc1 != null && enc2 != null) {
if (enc1 == enc2) return enc1;
if (obj2 instanceof RubyString && ((RubyString) obj2).getByteList().getRealSize() == 0) return enc1;

0 comments on commit cc90601

Please sign in to comment.