diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-03 11:09:25 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-03 11:09:25 +0000 |
commit | 4406629bd6f5841db014f9ec5aed860239182e05 (patch) | |
tree | 877255a1972376efd01492a1a18ef22636fcf94e /enc | |
parent | 8108417c5e4088b3b1ab6fe90a9a6d2ff9268892 (diff) |
* enc/trans/japanese.trans: new file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc')
-rw-r--r-- | enc/trans/japanese.trans | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/enc/trans/japanese.trans b/enc/trans/japanese.trans new file mode 100644 index 0000000000..279957b972 --- /dev/null +++ b/enc/trans/japanese.trans @@ -0,0 +1,96 @@ +#include "transcode_data.h" + +<% + map = {} + map["{00-7f}"] = :nomap + map["{a1-fe}{a1-fe}"] = :func_so + map["8e{a1-df}"] = :func_so + map["8e{e0-fe}"] = :undef + map["8f{a1-fe}{a1-fe}"] = :undef + transcode_generate_node(ActionMap.parse(map), "eucjp2sjis") + + map = {} + map["{00-7f}"] = :nomap + map["{81-9f,e0-ef}{40-7e,80-fc}"] = :func_so + map["{f0-fc}{40-7e,80-fc}"] = :undef + map["{a1-df}"] = :func_so + transcode_generate_node(ActionMap.parse(map), "sjis2eucjp") +%> + +<%= transcode_generated_code %> + +static int +fun_so_eucjp2sjis(rb_transcoding *t, const unsigned char *s, size_t l, unsigned char* o) +{ + if (s[0] == 0x8e) { + o[0] = s[1]; + return 1; + } + else { + int h, m, l; + m = s[0] & 1; + h = (s[0]+m) >> 1; + h += s[0] < 0xdf ? 0x30 : 0x70; + l = s[1] - m * 94 - 3; + if (0x7f <= l) + l++; + o[0] = h; + o[1] = l; + return 2; + } +} + +static int +fun_so_sjis2eucjp(rb_transcoding *t, const unsigned char *s, size_t l, unsigned char* o) +{ + if (l == 1) { + o[0] = '\x8e'; + o[1] = s[0]; + return 2; + } + else { + int h, m, l; + h = s[0]; + l = s[1]; + if (0xe0 <= h) + h -= 64; + l += l < 0x80 ? 0x61 : 0x60; + h = h * 2 - 0x61; + if (0xfe < l) { + l -= 94; + h += 1; + } + o[0] = h; + o[1] = l; + return 2; + } +} + +static const rb_transcoder +rb_eucjp2sjis = { + "EUC-JP", "Shift_JIS", eucjp2sjis, + TRANSCODE_TABLE_INFO, + 1, /* input_unit_length */ + 3, /* max_input */ + 2, /* max_output */ + stateless_converter, /* stateful_type */ + NULL, NULL, NULL, fun_so_eucjp2sjis +}; + +static const rb_transcoder +rb_sjis2eucjp = { + "Shift_JIS", "EUC-JP", sjis2eucjp, + TRANSCODE_TABLE_INFO, + 1, /* input_unit_length */ + 2, /* max_input */ + 2, /* max_output */ + stateless_converter, /* stateful_type */ + NULL, NULL, NULL, fun_so_sjis2eucjp +}; + +void +Init_japanese(void) +{ + rb_register_transcoder(&rb_eucjp2sjis); + rb_register_transcoder(&rb_sjis2eucjp); +} |