* transcode_data.h (TRANSCODE_ERROR): common transcode failure

exception, would be changed later.

* enc/trans/japanese.c (UNSUPPORTED_MODE): unsupported mode transition
  exception.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-08-05 03:34:52 +00:00
Родитель 578534bdda
Коммит b84d31c524
4 изменённых файлов: 59 добавлений и 45 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Tue Aug 5 12:34:49 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* transcode_data.h (TRANSCODE_ERROR): common transcode failure
exception, would be changed later.
* enc/trans/japanese.c (UNSUPPORTED_MODE): unsupported mode transition
exception.
Tue Aug 5 03:29:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Aug 5 03:29:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (rb_ary_sort_bang): respect overridden <=> for String and * array.c (rb_ary_sort_bang): respect overridden <=> for String and

Просмотреть файл

@ -23723,48 +23723,46 @@ enum ISO_2022_ESCSEQ {
#define ISO_2022_GZ_JIS_X_0213_2000_2 ISO_2022_ENCODING(ISO_2022_GZDM4,'P') #define ISO_2022_GZ_JIS_X_0213_2000_2 ISO_2022_ENCODING(ISO_2022_GZDM4,'P')
#define ISO_2022_GZ_JIS_X_0213_2004_1 ISO_2022_ENCODING(ISO_2022_GZDM4,'Q') #define ISO_2022_GZ_JIS_X_0213_2004_1 ISO_2022_ENCODING(ISO_2022_GZDM4,'Q')
#define UNSUPPORTED_MODE TRANSCODE_ERROR
static int static int
get_iso_2022_mode(const unsigned char **in_pos) get_iso_2022_mode(const unsigned char **in_pos)
{ {
int new_mode; int new_mode;
const unsigned char *in_p = *in_pos; const unsigned char *in_p = *in_pos;
switch (*in_p++) switch (*in_p++) {
{
case '(': case '(':
switch (*in_p++) switch (*in_p++) {
{
case 'B': case 'I': case 'J': case 'B': case 'I': case 'J':
new_mode = ISO_2022_ENCODING(ISO_2022_GZD4, *(in_p-1)); new_mode = ISO_2022_ENCODING(ISO_2022_GZD4, *(in_p-1));
break; break;
default: default:
rb_raise(rb_eRuntimeError /*change exception*/, "this mode is not supported (ESC ( %c)", *(in_p-1)); rb_raise(UNSUPPORTED_MODE, "this mode is not supported (ESC ( %c)", *(in_p-1));
break; break;
} }
break; break;
case '$': case '$':
switch (*in_p++) switch (*in_p++) {
{
case '@': case 'A': case 'B': case '@': case 'A': case 'B':
new_mode = ISO_2022_ENCODING(ISO_2022_GZDM4, *(in_p-1)); new_mode = ISO_2022_ENCODING(ISO_2022_GZDM4, *(in_p-1));
break; break;
case '(': case '(':
switch (*in_p++) switch (*in_p++) {
{
case 'D': case 'O': case 'P': case 'Q': case 'D': case 'O': case 'P': case 'Q':
new_mode = ISO_2022_ENCODING(ISO_2022_GZDM4, *(in_p-1)); new_mode = ISO_2022_ENCODING(ISO_2022_GZDM4, *(in_p-1));
break; break;
default: default:
rb_raise(rb_eRuntimeError /*change exception*/, "this mode is not supported (ESC $ ( %c)", *(in_p-1)); rb_raise(UNSUPPORTED_MODE, "this mode is not supported (ESC $ ( %c)", *(in_p-1));
break; break;
} }
break; break;
default: default:
rb_raise(rb_eRuntimeError /*change exception*/, "this mode is not supported (ESC $ %c)", *(in_p-1)); rb_raise(UNSUPPORTED_MODE, "this mode is not supported (ESC $ %c)", *(in_p-1));
break; break;
} }
break; break;
default: default:
rb_raise(rb_eRuntimeError /*change exception*/, "this mode is not supported (ESC %c)", *(in_p-1)); rb_raise(UNSUPPORTED_MODE, "this mode is not supported (ESC %c)", *(in_p-1));
break; break;
} }
*in_pos = in_p; *in_pos = in_p;
@ -23793,12 +23791,15 @@ from_iso_2022_jp_transcoder_preprocessor(const unsigned char **in_pos, unsigned
c1 = *in_p++; c1 = *in_p++;
if (c1 == 0x1B) { if (c1 == 0x1B) {
cur_mode = get_iso_2022_mode(&in_p); cur_mode = get_iso_2022_mode(&in_p);
} else if (c1 == 0x1E || c1 == 0x1F) { }
else if (c1 == 0x1E || c1 == 0x1F) {
/* SHIFT */ /* SHIFT */
rb_raise(rb_eRuntimeError /*change exception*/, "shift is not supported"); rb_raise(UNSUPPORTED_MODE, "shift is not supported");
} else if (c1 >= 0x80) { }
rb_raise(rb_eRuntimeError /*change exception*/, "invalid byte sequence"); else if (c1 >= 0x80) {
} else { rb_raise(TRANSCODE_ERROR, "invalid byte sequence");
}
else {
switch (cur_mode) { switch (cur_mode) {
case ISO_2022_GZ_ASCII: case ISO_2022_GZ_ASCII:
case ISO_2022_GZ_JIS_X_0201_Roman: case ISO_2022_GZ_JIS_X_0201_Roman:
@ -23828,8 +23829,7 @@ select_iso_2022_mode(unsigned char **out_pos, int new_mode)
{ {
unsigned char *out_p = *out_pos; unsigned char *out_p = *out_pos;
*out_p++ = '\x1b'; *out_p++ = '\x1b';
switch (new_mode>>8) switch (new_mode>>8) {
{
case ISO_2022_GZD4: case ISO_2022_GZD4:
*out_p++ = new_mode >> 8; *out_p++ = new_mode >> 8;
*out_p++ = new_mode & 0x7F; *out_p++ = new_mode & 0x7F;
@ -23845,7 +23845,7 @@ select_iso_2022_mode(unsigned char **out_pos, int new_mode)
*out_p++ = new_mode & 0x7F; *out_p++ = new_mode & 0x7F;
break; break;
default: default:
rb_raise(rb_eRuntimeError /*change exception*/, "this mode is not supported."); rb_raise(UNSUPPORTED_MODE, "this mode is not supported.");
break; break;
} }
*out_pos = out_p; *out_pos = out_p;
@ -23874,20 +23874,24 @@ to_iso_2022_jp_transcoder_postprocessor(const unsigned char **in_pos, unsigned c
next_byte = *in_p++; next_byte = *in_p++;
if (next_byte < 0x80) { if (next_byte < 0x80) {
new_mode = ISO_2022_GZ_ASCII; new_mode = ISO_2022_GZ_ASCII;
} else if (next_byte == 0x8E) { }
else if (next_byte == 0x8E) {
new_mode = ISO_2022_GZ_JIS_X_0201_Katakana; new_mode = ISO_2022_GZ_JIS_X_0201_Katakana;
next_byte = *in_p++; next_byte = *in_p++;
} else if (next_byte == 0x8F) { }
else if (next_byte == 0x8F) {
new_mode = ISO_2022_GZ_JIS_X_0212_1990; new_mode = ISO_2022_GZ_JIS_X_0212_1990;
next_byte = *in_p++; next_byte = *in_p++;
} else { }
else {
new_mode = ISO_2022_GZ_JIS_X_0208_1983; new_mode = ISO_2022_GZ_JIS_X_0208_1983;
} }
if (cur_mode != new_mode) if (cur_mode != new_mode)
cur_mode = select_iso_2022_mode(&out_p, new_mode); cur_mode = select_iso_2022_mode(&out_p, new_mode);
if (cur_mode < 0xFFFF) { if (cur_mode < 0xFFFF) {
*out_p++ = next_byte & 0x7F; *out_p++ = next_byte & 0x7F;
} else { }
else {
*out_p++ = next_byte & 0x7F; *out_p++ = next_byte & 0x7F;
*out_p++ = *in_p++ & 0x7F; *out_p++ = *in_p++ & 0x7F;
} }

Просмотреть файл

@ -274,7 +274,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
output_replacement_character(&out_p, to_encoding); output_replacement_character(&out_p, to_encoding);
continue; continue;
} }
rb_raise(rb_eRuntimeError /*change exception*/, "invalid byte sequence"); rb_raise(TRANSCODE_ERROR, "invalid byte sequence");
continue; continue;
undef: undef:
/* valid character in from encoding /* valid character in from encoding
@ -291,7 +291,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
output_replacement_character(&out_p, to_encoding); output_replacement_character(&out_p, to_encoding);
continue; continue;
} }
rb_raise(rb_eRuntimeError /*@@@change exception*/, "conversion undefined for byte sequence (maybe invalid byte sequence)"); rb_raise(TRANSCODE_ERROR, "conversion undefined for byte sequence (maybe invalid byte sequence)");
continue; continue;
} }
/* cleanup */ /* cleanup */

Просмотреть файл

@ -83,4 +83,6 @@ typedef struct rb_transcoder {
void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib); void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib);
void rb_register_transcoder(const rb_transcoder *); void rb_register_transcoder(const rb_transcoder *);
#define TRANSCODE_ERROR rb_eRuntimeError /*change exception*/
#endif /* RUBY_TRANSCODE_DATA_H */ #endif /* RUBY_TRANSCODE_DATA_H */