summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-20 06:12:48 +0000
committerduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-20 06:12:48 +0000
commit3d0c7bea4d2ad108889d0c4d81d41c4ff03f2a77 (patch)
tree049a03fa66fe12d5409b58e01596aa121402d390
parent66aeb2f7080dea92703f10546fb3cbcc946f6fa3 (diff)
Sun Jan 20 15:08:08 2008 Martin Duerst <duerst@it.aoyama.ac.jp>
* enc/trans/utf_16_32.c: new file, currently implementing UTF-16BE conversions only. * test/ruby/test_transcode.rb: Added tests for UTF-16BE; made check_both_ways() use force_encoding differently. * transcode_data.h, transcode.c: Support for more conversion functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--enc/trans/utf_16_32.c332
-rw-r--r--test/ruby/test_transcode.rb55
-rw-r--r--transcode.c13
-rw-r--r--transcode_data.h8
4 files changed, 404 insertions, 4 deletions
diff --git a/enc/trans/utf_16_32.c b/enc/trans/utf_16_32.c
new file mode 100644
index 0000000000..c0f5a7ab70
--- /dev/null
+++ b/enc/trans/utf_16_32.c
@@ -0,0 +1,332 @@
+/* Autogenerated, do not change */
+/* Report bugs to Martin Duerst (duerst@it.aoyama.ac.jp) */
+
+#include "transcode_data.h"
+
+static int
+fun_so_from_utf_16be(const unsigned char* s, unsigned char* o)
+{
+ if (!s[0] && s[1]<0x80) {
+ o[0] = s[1];
+ return 1;
+ }
+ else if (s[0]<0x08) {
+ o[0] = 0xC0 | (s[0]<<2) | (s[1]>>6);
+ o[1] = 0x80 | s[1]&0x3F;
+ return 2;
+ }
+ else if ((s[0]&0xF8)!=0xD8) {
+ o[0] = 0xE0 | s[0]>>4;
+ o[1] = 0x80 | ((s[0]&0x0F)<<2) | (s[1]>>6);
+ o[2] = 0x80 | s[1]&0x3F;
+ return 3;
+ }
+ else {
+ unsigned int u = (((s[0]&0x03)<<2)|(s[1]>>6)) + 1;
+ o[0] = 0xF0 | u>>2;
+ o[1] = 0x80 | ((u&0x03)<<4) | (s[1]>>2)&0x0F;
+ o[2] = 0x80 | ((s[1]&0x03)<<4) | ((s[2]&0x03)<<2) | (s[3]>>6);
+ o[3] = 0x80 | s[3]&0x3F;
+ return 4;
+ }
+}
+
+static int
+fun_so_to_utf_16be(const unsigned char* s, unsigned char* o)
+{
+ if (!(s[0]&0x80)) {
+ o[0] = 0x00;
+ o[1] = s[0];
+ return 2;
+ }
+ else if ((s[0]&0xE0)==0xC0) {
+ o[0] = (s[0]>>2)&0x07;
+ o[1] = ((s[0]&0x03)<<6) | s[1]&0x3F;
+ return 2;
+ }
+ else if ((s[0]&0xF0)==0xE0) {
+ o[0] = (s[0]<<4) | (s[1]>>2)^0x20;
+ o[1] = (s[1]<<6) | s[2]^0x80;
+ return 2;
+ }
+ else {
+ int w = (((s[0]&0x07)<<2) | (s[1]>>4)&0x03) - 1;
+ o[0] = 0xD8 | (w>>2);
+ o[1] = (w<<6) | ((s[1]&0x0F)<<2) | ((s[2]>>4)-8);
+ o[2] = 0xDC | ((s[2]>>2)&0x03);
+ o[3] = (s[2]<<6) | (s[3]&~0x80);
+ return 4;
+ }
+}
+static const unsigned char
+from_UTF_16BE_00_offsets[256] = {
+ /* used by from_UTF_16BE_00 */
+ /* used by from_UTF_16BE_D8 */
+ /* used by from_UTF_16BE_D8_00_00 */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+static const struct byte_lookup* const
+from_UTF_16BE_00_infos[1] = {
+ /* used by from_UTF_16BE_00 */
+ /* used by to_UTF_16BE_82 */
+ FUNso,
+};
+static const BYTE_LOOKUP
+from_UTF_16BE_00 = {
+ /* used as from_UTF_16BE */
+ /* used as from_UTF_16BE_D8_00 */
+ from_UTF_16BE_00_offsets,
+ from_UTF_16BE_00_infos
+};
+
+static const struct byte_lookup* const
+from_UTF_16BE_D8_00_00_infos[1] = {
+ INVALID,
+};
+static const BYTE_LOOKUP
+from_UTF_16BE_D8_00_00 = {
+ /* used as from_UTF_16BE_D8_00 */
+ /* used as from_UTF_16BE */
+ from_UTF_16BE_00_offsets,
+ from_UTF_16BE_D8_00_00_infos
+};
+
+static const unsigned char
+from_UTF_16BE_D8_00_offsets[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+static const struct byte_lookup* const
+from_UTF_16BE_D8_00_infos[2] = {
+ &from_UTF_16BE_D8_00_00, &from_UTF_16BE_00,
+};
+static const BYTE_LOOKUP
+from_UTF_16BE_D8_00 = {
+ from_UTF_16BE_D8_00_offsets,
+ from_UTF_16BE_D8_00_infos
+};
+
+static const struct byte_lookup* const
+from_UTF_16BE_D8_infos[1] = {
+ &from_UTF_16BE_D8_00,
+};
+static const BYTE_LOOKUP
+from_UTF_16BE_D8 = {
+ from_UTF_16BE_00_offsets,
+ from_UTF_16BE_D8_infos
+};
+
+static const unsigned char
+from_UTF_16BE_offsets[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+static const struct byte_lookup* const
+from_UTF_16BE_infos[3] = {
+ &from_UTF_16BE_00, &from_UTF_16BE_D8,
+ &from_UTF_16BE_D8_00_00,
+};
+static const BYTE_LOOKUP
+from_UTF_16BE = {
+ from_UTF_16BE_offsets,
+ from_UTF_16BE_infos
+};
+
+static rb_transcoder
+rb_from_UTF_16BE = {
+ "UTF-16BE", "UTF-8", &from_UTF_16BE, 4, 0,
+ NULL, NULL, NULL, NULL, NULL, &fun_so_from_utf_16be
+};
+
+static const unsigned char
+to_UTF_16BE_82_offsets[64] = {
+ /* used by to_UTF_16BE_82 */
+ /* used by to_UTF_16BE_E1 */
+ /* used by to_UTF_16BE_F1 */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE_82 = {
+ /* used as to_UTF_16BE */
+ /* used as to_UTF_16BE_E0 */
+ /* used as to_UTF_16BE_E1 */
+ /* used as to_UTF_16BE_ED */
+ /* used as to_UTF_16BE_F0_90 */
+ /* used as to_UTF_16BE_F1_80 */
+ /* used as to_UTF_16BE_F4_80 */
+ to_UTF_16BE_82_offsets,
+ from_UTF_16BE_00_infos
+};
+
+static const unsigned char
+to_UTF_16BE_E0_offsets[64] = {
+ /* used by to_UTF_16BE_E0 */
+ /* used by to_UTF_16BE_ED */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+};
+static const struct byte_lookup* const
+to_UTF_16BE_E0_infos[2] = {
+ INVALID, &to_UTF_16BE_82,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE_E0 = {
+ to_UTF_16BE_E0_offsets,
+ to_UTF_16BE_E0_infos
+};
+
+static const struct byte_lookup* const
+to_UTF_16BE_E1_infos[1] = {
+ &to_UTF_16BE_82,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE_E1 = {
+ /* used as to_UTF_16BE */
+ /* used as to_UTF_16BE_F0 */
+ /* used as to_UTF_16BE_F1 */
+ /* used as to_UTF_16BE_F4 */
+ to_UTF_16BE_82_offsets,
+ to_UTF_16BE_E1_infos
+};
+
+static const struct byte_lookup* const
+to_UTF_16BE_ED_infos[2] = {
+ &to_UTF_16BE_82, INVALID,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE_ED = {
+ to_UTF_16BE_E0_offsets,
+ to_UTF_16BE_ED_infos
+};
+
+static const unsigned char
+to_UTF_16BE_F0_offsets[64] = {
+ /* used by to_UTF_16BE_F0 */
+ /* used by to_UTF_16BE_F4 */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+};
+static const struct byte_lookup* const
+to_UTF_16BE_F0_infos[2] = {
+ INVALID, &to_UTF_16BE_E1,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE_F0 = {
+ to_UTF_16BE_F0_offsets,
+ to_UTF_16BE_F0_infos
+};
+
+static const struct byte_lookup* const
+to_UTF_16BE_F1_infos[1] = {
+ &to_UTF_16BE_E1,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE_F1 = {
+ to_UTF_16BE_82_offsets,
+ to_UTF_16BE_F1_infos
+};
+
+static const struct byte_lookup* const
+to_UTF_16BE_F4_infos[2] = {
+ &to_UTF_16BE_E1, INVALID,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE_F4 = {
+ to_UTF_16BE_F0_offsets,
+ to_UTF_16BE_F4_infos
+};
+
+static const unsigned char
+to_UTF_16BE_offsets[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 4,
+ 6, 7, 7, 7, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+};
+static const struct byte_lookup* const
+to_UTF_16BE_infos[9] = {
+ FUNso, INVALID, &to_UTF_16BE_82, &to_UTF_16BE_E0,
+ &to_UTF_16BE_E1, &to_UTF_16BE_ED, &to_UTF_16BE_F0, &to_UTF_16BE_F1,
+ &to_UTF_16BE_F4,
+};
+static const BYTE_LOOKUP
+to_UTF_16BE = {
+ to_UTF_16BE_offsets,
+ to_UTF_16BE_infos
+};
+
+static rb_transcoder
+rb_to_UTF_16BE = {
+ "UTF-8", "UTF-16BE", &to_UTF_16BE, 4, 1,
+ NULL, NULL, NULL, NULL, NULL, &fun_so_to_utf_16be
+};
+
+void
+Init_utf_16_32(void)
+{
+ rb_register_transcoder(&rb_from_UTF_16BE);
+ rb_register_transcoder(&rb_to_UTF_16BE);
+}
+/* Footprint (bytes): gross: 3420, saved: 1992, net: 1428 */
diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb
index 4b3e1e77f3..cf5600926d 100644
--- a/test/ruby/test_transcode.rb
+++ b/test/ruby/test_transcode.rb
@@ -10,7 +10,8 @@ class TestTranscode < Test::Unit::TestCase
'ISO-8859-7', 'ISO-8859-8',
'ISO-8859-9', 'ISO-8859-10',
'ISO-8859-11', 'ISO-8859-13',
- 'ISO-8859-14', 'ISO-8859-15'
+ 'ISO-8859-14', 'ISO-8859-15',
+ 'UTF-16BE'
]
all_encodings.each do |enc|
'abc'.encode(enc, 'UTF-8')
@@ -54,8 +55,8 @@ class TestTranscode < Test::Unit::TestCase
end
def check_both_ways(utf8, raw, encoding)
- assert_equal(utf8, raw.encode('utf-8', encoding))
- assert_equal(raw, utf8.encode(encoding).force_encoding('ASCII-8BIT'))
+ assert_equal(utf8.force_encoding('utf-8'), raw.encode('utf-8', encoding))
+ assert_equal(raw.force_encoding(encoding), utf8.encode(encoding, 'utf-8'))
end
def test_encodings
@@ -124,4 +125,52 @@ class TestTranscode < Test::Unit::TestCase
assert_equal(test_start, test_start.encode('UTF-8',enc).encode(enc).force_encoding('ASCII-8BIT'))
end
end
+
+ def test_utf_16be
+ check_both_ways("abc".force_encoding('UTF-8'), "\x00a\x00b\x00c", 'utf-16be')
+ check_both_ways("\u00E9", "\x00\xE9", 'utf-16be');
+ check_both_ways("\u00E9\u0070\u00E9\u0065", "\x00\xE9\x00\x70\x00\xE9\x00\x65", 'utf-16be') # épée
+ check_both_ways("\u677E\u672C\u884C\u5F18", "\x67\x7E\x67\x2C\x88\x4C\x5F\x18", 'utf-16be') # 松本行弘
+ check_both_ways("\u9752\u5C71\u5B66\u9662\u5927\u5B66", "\x97\x52\x5C\x71\x5B\x66\x96\x62\x59\x27\x5B\x66",
+ 'utf-16be') # 青山学院大学
+ check_both_ways("Martin D\u00FCrst", "\x00M\x00a\x00r\x00t\x00i\x00n\x00 \x00D\x00\xFC\x00r\x00s\x00t",
+ 'utf-16be') # Martin Dürst
+ # BMP
+ check_both_ways("\u0000", "\x00\x00", 'utf-16be')
+ check_both_ways("\u007F", "\x00\x7F", 'utf-16be')
+ check_both_ways("\u0080", "\x00\x80", 'utf-16be')
+ check_both_ways("\u0555", "\x05\x55", 'utf-16be')
+ check_both_ways("\u04AA", "\x04\xAA", 'utf-16be')
+ check_both_ways("\u0333", "\x03\x33", 'utf-16be')
+ check_both_ways("\u04CC", "\x04\xCC", 'utf-16be')
+ check_both_ways("\u00F0", "\x00\xF0", 'utf-16be')
+ check_both_ways("\u070F", "\x07\x0F", 'utf-16be')
+ check_both_ways("\u07FF", "\x07\xFF", 'utf-16be')
+ check_both_ways("\u0800", "\x08\x00", 'utf-16be')
+ check_both_ways("\uD7FF", "\xD7\xFF", 'utf-16be')
+ check_both_ways("\uE000", "\xE0\x00", 'utf-16be')
+ check_both_ways("\uFFFF", "\xFF\xFF", 'utf-16be')
+ check_both_ways("\u5555", "\x55\x55", 'utf-16be')
+ check_both_ways("\uAAAA", "\xAA\xAA", 'utf-16be')
+ check_both_ways("\u3333", "\x33\x33", 'utf-16be')
+ check_both_ways("\uCCCC", "\xCC\xCC", 'utf-16be')
+ check_both_ways("\uF0F0", "\xF0\xF0", 'utf-16be')
+ check_both_ways("\u0F0F", "\x0F\x0F", 'utf-16be')
+ check_both_ways("\uFF00", "\xFF\x00", 'utf-16be')
+ check_both_ways("\u00FF", "\x00\xFF", 'utf-16be')
+ # outer planes
+ check_both_ways("\u{10000}", "\xD8\x00\xDC\x00", 'utf-16be')
+ check_both_ways("\u{FFFFF}", "\xDB\xBF\xDF\xFF", 'utf-16be')
+ check_both_ways("\u{100000}", "\xDB\xC0\xDC\x00", 'utf-16be')
+ check_both_ways("\u{10FFFF}", "\xDB\xFF\xDF\xFF", 'utf-16be')
+ check_both_ways("\u{105555}", "\xDB\xD5\xDD\x55", 'utf-16be')
+ check_both_ways("\u{55555}", "\xD9\x15\xDD\x55", 'utf-16be')
+ check_both_ways("\u{AAAAA}", "\xDA\x6A\xDE\xAA", 'utf-16be')
+ check_both_ways("\u{33333}", "\xD8\x8C\xDF\x33", 'utf-16be')
+ check_both_ways("\u{CCCCC}", "\xDA\xF3\xDC\xCC", 'utf-16be')
+ check_both_ways("\u{8F0F0}", "\xD9\xFC\xDC\xF0", 'utf-16be')
+ check_both_ways("\u{F0F0F}", "\xDB\x83\xDF\x0F", 'utf-16be')
+ check_both_ways("\u{8FF00}", "\xD9\xFF\xDF\x00", 'utf-16be')
+ check_both_ways("\u{F00FF}", "\xDB\x80\xDC\xFF", 'utf-16be')
+ end
end
diff --git a/transcode.c b/transcode.c
index 8c69185414..1a6efc6100 100644
--- a/transcode.c
+++ b/transcode.c
@@ -104,6 +104,7 @@ init_transcoder_table(void)
rb_declare_transcoder("SHIFT_JIS", "UTF-8", "japanese");
rb_declare_transcoder("EUC-JP", "UTF-8", "japanese");
rb_declare_transcoder("ISO-2022-JP", "UTF-8", "japanese");
+ rb_declare_transcoder("UTF-16BE", "UTF-8", "utf_16_32");
}
#define encoding_equal(enc1, enc2) (STRCASECMP(enc1, enc2) == 0)
@@ -153,12 +154,14 @@ transcode_loop(char **in_pos, char **out_pos,
char *in_p = *in_pos, *out_p = *out_pos;
const BYTE_LOOKUP *conv_tree_start = my_transcoder->conv_tree_start;
const BYTE_LOOKUP *next_table;
+ char *char_start;
unsigned int next_offset;
VALUE next_info;
unsigned char next_byte;
int from_utf8 = my_transcoder->from_utf8;
char *out_s = out_stop - my_transcoder->max_output + 1;
while (in_p < in_stop) {
+ char_start = in_p;
next_table = conv_tree_start;
if (out_p >= out_s) {
int len = (out_p - *out_pos);
@@ -212,6 +215,16 @@ transcode_loop(char **in_pos, char **out_pos,
case FUNii:
next_info = (VALUE)(*my_transcoder->func_ii)(next_info);
goto follow_info;
+ case FUNsi:
+ next_info = (VALUE)(*my_transcoder->func_si)(char_start);
+ goto follow_info;
+ break;
+ case FUNio:
+ out_p += (VALUE)(*my_transcoder->func_io)(next_info, out_p);
+ break;
+ case FUNso:
+ out_p += (VALUE)(*my_transcoder->func_so)(char_start, out_p);
+ break;
case INVALID:
goto invalid;
case UNDEF:
diff --git a/transcode_data.h b/transcode_data.h
index 65929390b9..8d0c8ccf33 100644
--- a/transcode_data.h
+++ b/transcode_data.h
@@ -35,6 +35,9 @@ typedef struct byte_lookup {
#define UNDEF (PType 0x09) /* legal but undefined */
#define ZERObt (PType 0x0A) /* zero bytes of payload, i.e. remove */
#define FUNii (PType 0x0B) /* function from info to info */
+#define FUNsi (PType 0x0D) /* function from start to info */
+#define FUNio (PType 0x0E) /* function from info to output */
+#define FUNso (PType 0x0F) /* function from start to output */
#define o1(b1) (PType((((unsigned char)(b1))<<8)|ONEbt))
#define o2(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))
@@ -72,7 +75,10 @@ typedef struct rb_transcoder {
struct rb_transcoder *, struct rb_transcoding *);
void (*postprocessor)(char**, char**, char*, char*,
struct rb_transcoder *, struct rb_transcoding *);
- VALUE (*func_ii)(VALUE); /* function from info to info */
+ VALUE (*func_ii)(VALUE); /* info -> info */
+ VALUE (*func_si)(const unsigned char* const); /* start -> info */
+ int (*func_io)(VALUE, const unsigned char*); /* info -> output */
+ int (*func_so)(const unsigned char*, unsigned char*); /* start -> output */
} rb_transcoder;
void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib);