diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-11-23 20:49:56 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-11-23 20:49:56 +0000 |
commit | 7f38397b6c01b65219deb622c027e177bdc23ede (patch) | |
tree | e798702443d0680dbf47e809820b34a4dec328ed /enc/trans | |
parent | 3ab82a65d701db47cea2ccbe9e7821468e71dd90 (diff) | |
download | ruby-7f38397b6c01b65219deb622c027e177bdc23ede.tar.gz |
* enc/trans/utf_16_32.trans: add a convert from UTF-8 to UTF-16.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc/trans')
-rw-r--r-- | enc/trans/utf_16_32.trans | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/enc/trans/utf_16_32.trans b/enc/trans/utf_16_32.trans index 2d7005993e..01caffe02c 100644 --- a/enc/trans/utf_16_32.trans +++ b/enc/trans/utf_16_32.trans @@ -289,7 +289,7 @@ fun_si_from_utf_16(void *statep, const unsigned char *s, size_t l) } break; case BE: - if (s[0] < 0xD8 && 0xDF < s[0]) { + if (s[0] < 0xD8 || 0xDF < s[0]) { return (VALUE)FUNso; } else if (s[0] <= 0xDB) { @@ -297,7 +297,7 @@ fun_si_from_utf_16(void *statep, const unsigned char *s, size_t l) } break; case LE: - if (s[1] < 0xD8 && 0xDF < s[1]) { + if (s[1] < 0xD8 || 0xDF < s[1]) { return (VALUE)FUNso; } else if (s[1] <= 0xDB) { @@ -321,6 +321,19 @@ fun_so_from_utf_16(void *statep, const unsigned char *s, size_t l, unsigned char return 0; } +static ssize_t +fun_so_to_utf_16(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize) +{ + unsigned char *sp = statep; + if (*sp == 0) { + *o++ = 0xFE; + *o++ = 0xFF; + *sp = 1; + return 2 + fun_so_to_utf_16be(statep, s, l, o, osize); + } + return fun_so_to_utf_16be(statep, s, l, o, osize); +} + static const rb_transcoder rb_from_UTF_16BE = { "UTF-16BE", "UTF-8", from_UTF_16BE, @@ -429,6 +442,18 @@ rb_from_UTF_16 = { NULL, fun_si_from_utf_16, NULL, fun_so_from_utf_16 }; +static const rb_transcoder +rb_to_UTF_16 = { + "UTF-8", "UTF-16", from_UTF_8, + TRANSCODE_TABLE_INFO, + 1, /* input_unit_length */ + 4, /* max_input */ + 4, /* max_output */ + asciicompat_encoder, /* asciicompat_type */ + 1, state_init, NULL, /* state_size, state_init, state_fini */ + NULL, NULL, NULL, fun_so_to_utf_16 +}; + void Init_utf_16_32(void) { @@ -441,4 +466,5 @@ Init_utf_16_32(void) rb_register_transcoder(&rb_from_UTF_32LE); rb_register_transcoder(&rb_to_UTF_32LE); rb_register_transcoder(&rb_from_UTF_16); + rb_register_transcoder(&rb_to_UTF_16); } |