From 14a85c09bda3fe65509e1e681aff76af00418284 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 14 Aug 2008 14:28:10 +0000 Subject: * include/ruby/encoding.h (rb_econv_result_t): moved from transcode_data.h. (rb_econv_elem_t): ditto. (rb_econv_t): ditto. source_encoding and destination_encoding field is added. (rb_econv_open): declared. (rb_econv_convert): ditto. (rb_econv_close): ditto. * transcode.c (rb_econv_open_by_transcoder_entries): initialize source_encoding and destination_encoding field as NULL. (rb_econv_open): make it external linkage. (rb_econv_close): ditto. (rb_econv_convert): ditto. renamed from rb_econv_conv. (make_encoding): new function. (econv_init): use make_encoding and store rb_encoding* in rb_econv_t. (econv_source_encoding): new method Encoding::Converter#source_encoding. (econv_destination_encoding): new method Encoding::Converter#destination_encoding. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- include/ruby/encoding.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'include/ruby/encoding.h') diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index c301b8458..90828f6c2 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -196,4 +196,45 @@ rb_enc_dummy_p(rb_encoding *enc) VALUE rb_str_transcode(VALUE str, VALUE to); +/* econv stuff */ + +typedef enum { + econv_invalid_byte_sequence, + econv_undefined_conversion, + econv_destination_buffer_full, + econv_source_buffer_empty, + econv_finished, + econv_output_followed_by_input, +} rb_econv_result_t; + +typedef struct { + const char *from; + const char *to; + struct rb_transcoding *tc; + unsigned char *out_buf_start; + unsigned char *out_data_start; + unsigned char *out_data_end; + unsigned char *out_buf_end; + rb_econv_result_t last_result; +} rb_econv_elem_t; + +typedef struct { + rb_econv_elem_t *elems; + int num_trans; + int num_finished; + struct rb_transcoding *last_tc; + + /* The following fields are only for Encoding::Converter. + * rb_econv_open set them NULL. */ + rb_encoding *source_encoding; + rb_encoding *destination_encoding; +} rb_econv_t; + +rb_econv_t *rb_econv_open(const char *from, const char *to, int flags); +rb_econv_result_t rb_econv_convert(rb_econv_t *ec, + const unsigned char **input_ptr, const unsigned char *input_stop, + unsigned char **output_ptr, unsigned char *output_stop, + int flags); +void rb_econv_close(rb_econv_t *ec); + #endif /* RUBY_ENCODING_H */ -- cgit