Permalink
Browse files

handle -unix, -dos, -mac special encoding suffixes

  • Loading branch information...
1 parent ffd31a3 commit 2b78929b7dbea7a76829f776a5c787168dcdbc42 @quix committed Aug 3, 2011
@@ -12,7 +12,15 @@ def self.read(file)
# magic comment overrides BOM
encoding = contents[MAGIC_COMMENT, 1] || utf8 || "US-ASCII"
- contents.force_encoding(encoding)
+ contents.force_encoding(strip_special(encoding))
+ end
+
+ def self.strip_special(encoding)
+ if encoding =~ /\Autf8-mac\Z/i
+ "UTF8-MAC"
+ else
+ encoding.sub(/-(unix|dos|mac)\Z/i, "")
+ end
end
end
end
@@ -5,6 +5,10 @@ class AllEncodingTest < RegularTest
default US-ASCII
usascii US-ASCII
utf8 UTF-8
+ utf8unix UTF-8
+ utf8mac UTF-8
+ utf8mac_alt UTF8-MAC
+ utf8dos UTF-8
utf8bom UTF-8
utf8bom_only UTF-8
usascii_with_utf8bom US-ASCII
@@ -0,0 +1,6 @@
+# -*- coding: utf-8-dos -*-
+module EncodingTest
+ def utf8dos_string
+ "大きな箱とねこ。"
+ end
+end
@@ -0,0 +1,6 @@
+# -*- coding: utf-8-mac -*-
+module EncodingTest
+ def utf8mac_string
+ "大きな箱とねこ。"
+ end
+end
@@ -0,0 +1,6 @@
+# -*- coding: utf8-mac -*-
+module EncodingTest
+ def utf8mac_alt_string
+ "大きな箱とねこ。"
+ end
+end
@@ -0,0 +1,6 @@
+# -*- coding: utf-8-unix -*-
+module EncodingTest
+ def utf8unix_string
+ "大きな箱とねこ。"
+ end
+end

0 comments on commit 2b78929

Please sign in to comment.