From 2078eb35ec58db6cf2e62f6e75ba1e8b7f9ddb21 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 3 Sep 2008 14:34:09 +0000 Subject: * transcode.c (rb_transcoding): moved from transcode_data.h. (TRANSCODING_READBUF): ditto. (TRANSCODING_WRITEBUF): ditto. (TRANSCODING_STATE_EMBED_MAX): ditto. (TRANSCODING_STATE): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- transcode.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'transcode.c') diff --git a/transcode.c b/transcode.c index ca772ce84..aa605f830 100644 --- a/transcode.c +++ b/transcode.c @@ -31,6 +31,48 @@ static VALUE sym_finished; static VALUE sym_output_followed_by_input; static VALUE sym_incomplete_input; +/* dynamic structure, one per conversion (similar to iconv_t) */ +/* may carry conversion state (e.g. for iso-2022-jp) */ +typedef struct rb_transcoding { + const rb_transcoder *transcoder; + + int flags; + + int resume_position; + unsigned int next_table; + VALUE next_info; + unsigned char next_byte; + + int recognized_len; /* already interpreted */ + int readagain_len; /* not yet interpreted */ + union { + unsigned char ary[8]; /* max_input <= sizeof(ary) */ + unsigned char *ptr; /* length: max_input */ + } readbuf; /* recognized_len + readagain_len used */ + + int writebuf_off; + int writebuf_len; + union { + unsigned char ary[8]; /* max_output <= sizeof(ary) */ + unsigned char *ptr; /* length: max_output */ + } writebuf; + + void *state; /* opaque data for stateful encoding */ +} rb_transcoding; +#define TRANSCODING_READBUF(tc) \ + ((tc)->transcoder->max_input <= sizeof((tc)->readbuf.ary) ? \ + (tc)->readbuf.ary : \ + (tc)->readbuf.ptr) +#define TRANSCODING_WRITEBUF(tc) \ + ((tc)->transcoder->max_output <= sizeof((tc)->writebuf.ary) ? \ + (tc)->writebuf.ary : \ + (tc)->writebuf.ptr) +#define TRANSCODING_STATE_EMBED_MAX sizeof(void *) +#define TRANSCODING_STATE(tc) \ + ((tc)->transcoder->state_size <= sizeof((tc)->state) ? \ + (void *)&(tc)->state : \ + (tc)->state) + typedef struct { struct rb_transcoding *tc; unsigned char *out_buf_start; -- cgit