Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Typedefs | Functions | Variables
transcode.c File Reference
#include "internal.h"
#include "transcode_data.h"
#include <ctype.h>

Go to the source code of this file.

Data Structures

struct  rb_transcoding
 
union  rb_transcoding::rb_transcoding_state_t
 
struct  rb_econv_elem_t
 
struct  rb_econv_t
 
struct  transcoder_entry_t
 
struct  search_path_queue_tag
 
struct  search_path_bfs_t
 
struct  trans_open_t
 
struct  asciicompat_encoding_t
 
struct  rb_econv_init_by_convpath_t
 

Macros

#define ENABLE_ECONV_NEWLINE_OPTION   1
 
#define TRANSCODING_READBUF(tc)
 
#define TRANSCODING_WRITEBUF(tc)
 
#define TRANSCODING_WRITEBUF_SIZE(tc)
 
#define TRANSCODING_STATE_EMBED_MAX   ((int)sizeof(union rb_transcoding_state_t))
 
#define TRANSCODING_STATE(tc)
 
#define DECORATOR_P(sname, dname)   (*(sname) == '\0')
 
#define encoding_equal(enc1, enc2)   (STRCASECMP((enc1), (enc2)) == 0)
 
#define SUSPEND(ret, num)
 
#define SUSPEND_OBUF(num)
 
#define SUSPEND_AFTER_OUTPUT(num)
 
#define next_table   (tc->next_table)
 
#define next_info   (tc->next_info)
 
#define next_byte   (tc->next_byte)
 
#define writebuf_len   (tc->writebuf_len)
 
#define writebuf_off   (tc->writebuf_off)
 
#define BYTE_ADDR(index)   (tr->byte_array + (index))
 
#define WORD_ADDR(index)   (tr->word_array + INFO2WORDINDEX(index))
 
#define BL_BASE   BYTE_ADDR(BYTE_LOOKUP_BASE(WORD_ADDR(next_table)))
 
#define BL_INFO   WORD_ADDR(BYTE_LOOKUP_INFO(WORD_ADDR(next_table)))
 
#define BL_MIN_BYTE   (BL_BASE[0])
 
#define BL_MAX_BYTE   (BL_BASE[1])
 
#define BL_OFFSET(byte)   (BL_BASE[2+(byte)-BL_MIN_BYTE])
 
#define BL_ACTION(byte)   (BL_INFO[BL_OFFSET((byte))])
 
#define MAX_ECFLAGS_DECORATORS   32
 
#define hash_fallback   rb_hash_aref
 

Typedefs

typedef struct rb_transcoding rb_transcoding
 
typedef struct search_path_queue_tag search_path_queue_t
 

Functions

void rb_register_transcoder (const rb_transcoder *tr)
 
void rb_declare_transcoder (const char *enc1, const char *enc2, const char *lib)
 
rb_econv_trb_econv_open (const char *sname, const char *dname, int ecflags)
 
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)
 
const char * rb_econv_encoding_to_insert_output (rb_econv_t *ec)
 
int rb_econv_insert_output (rb_econv_t *ec, const unsigned char *str, size_t len, const char *str_encoding)
 
void rb_econv_close (rb_econv_t *ec)
 
size_t rb_econv_memsize (rb_econv_t *ec)
 
int rb_econv_putbackable (rb_econv_t *ec)
 
void rb_econv_putback (rb_econv_t *ec, unsigned char *p, int n)
 
const char * rb_econv_asciicompat_encoding (const char *ascii_incompat_name)
 
VALUE rb_econv_append (rb_econv_t *ec, const char *ss, long len, VALUE dst, int flags)
 
VALUE rb_econv_substr_append (rb_econv_t *ec, VALUE src, long off, long len, VALUE dst, int flags)
 
VALUE rb_econv_str_append (rb_econv_t *ec, VALUE src, VALUE dst, int flags)
 
VALUE rb_econv_substr_convert (rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags)
 
VALUE rb_econv_str_convert (rb_econv_t *ec, VALUE src, int flags)
 
int rb_econv_decorate_at_first (rb_econv_t *ec, const char *decorator_name)
 
int rb_econv_decorate_at_last (rb_econv_t *ec, const char *decorator_name)
 
void rb_econv_binmode (rb_econv_t *ec)
 
VALUE rb_econv_open_exc (const char *sname, const char *dname, int ecflags)
 
int rb_econv_set_replacement (rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname)
 
int rb_econv_prepare_options (VALUE opthash, VALUE *opts, int ecflags)
 
int rb_econv_prepare_opts (VALUE opthash, VALUE *opts)
 
rb_econv_trb_econv_open_opts (const char *source_encoding, const char *destination_encoding, int ecflags, VALUE opthash)
 
VALUE rb_str_encode (VALUE str, VALUE to, int ecflags, VALUE ecopts)
 
int rb_econv_has_convpath_p (const char *from_encoding, const char *to_encoding)
 
VALUE rb_econv_make_exception (rb_econv_t *ec)
 
void rb_econv_check_error (rb_econv_t *ec)
 
void Init_transcode (void)
 
void InitVM_transcode (void)
 

Variables

VALUE rb_eUndefinedConversionError
 
VALUE rb_eInvalidByteSequenceError
 
VALUE rb_eConverterNotFoundError
 
VALUE rb_cEncodingConverter
 

Macro Definition Documentation

◆ BL_ACTION

#define BL_ACTION (   byte)    (BL_INFO[BL_OFFSET((byte))])

◆ BL_BASE

◆ BL_INFO

◆ BL_MAX_BYTE

#define BL_MAX_BYTE   (BL_BASE[1])

◆ BL_MIN_BYTE

#define BL_MIN_BYTE   (BL_BASE[0])

◆ BL_OFFSET

#define BL_OFFSET (   byte)    (BL_BASE[2+(byte)-BL_MIN_BYTE])

◆ BYTE_ADDR

#define BYTE_ADDR (   index)    (tr->byte_array + (index))

◆ DECORATOR_P

#define DECORATOR_P (   sname,
  dname 
)    (*(sname) == '\0')

Definition at line 152 of file transcode.c.

◆ ENABLE_ECONV_NEWLINE_OPTION

#define ENABLE_ECONV_NEWLINE_OPTION   1

Definition at line 16 of file transcode.c.

◆ encoding_equal

#define encoding_equal (   enc1,
  enc2 
)    (STRCASECMP((enc1), (enc2)) == 0)

Definition at line 239 of file transcode.c.

Referenced by rb_econv_insert_output(), and rb_econv_set_replacement().

◆ hash_fallback

#define hash_fallback   rb_hash_aref

Definition at line 2242 of file transcode.c.

◆ MAX_ECFLAGS_DECORATORS

#define MAX_ECFLAGS_DECORATORS   32

Definition at line 1022 of file transcode.c.

Referenced by rb_econv_open().

◆ next_byte

#define next_byte   (tc->next_byte)

◆ next_info

#define next_info   (tc->next_info)

◆ next_table

#define next_table   (tc->next_table)

◆ SUSPEND

#define SUSPEND (   ret,
  num 
)
Value:
do { \
tc->resume_position = (num); \
if (0 < in_p - inchar_start) \
MEMMOVE(TRANSCODING_READBUF(tc)+tc->recognized_len, \
inchar_start, unsigned char, in_p - inchar_start); \
*in_pos = in_p; \
*out_pos = out_p; \
tc->recognized_len += in_p - inchar_start; \
if (readagain_len) { \
tc->recognized_len -= readagain_len; \
tc->readagain_len = readagain_len; \
} \
return (ret); \
resume_label ## num:; \
} while (0)
#define TRANSCODING_READBUF(tc)
Definition: transcode.c:82

◆ SUSPEND_AFTER_OUTPUT

#define SUSPEND_AFTER_OUTPUT (   num)
Value:
if ((opt & ECONV_AFTER_OUTPUT) && *out_pos != out_p) { \
SUSPEND(econv_after_output, num); \
}
#define ECONV_AFTER_OUTPUT
Definition: encoding.h:410

◆ SUSPEND_OBUF

#define SUSPEND_OBUF (   num)
Value:
do { \
while (out_stop - out_p < 1) { SUSPEND(econv_destination_buffer_full, num); } \
} while (0)
#define SUSPEND(ret, num)

◆ TRANSCODING_READBUF

#define TRANSCODING_READBUF (   tc)
Value:
((tc)->transcoder->max_input <= (int)sizeof((tc)->readbuf.ary) ? \
(tc)->readbuf.ary : \
(tc)->readbuf.ptr)

Definition at line 82 of file transcode.c.

Referenced by rb_econv_putback().

◆ TRANSCODING_STATE

#define TRANSCODING_STATE (   tc)
Value:
((tc)->transcoder->state_size <= (int)sizeof((tc)->state) ? \
(tc)->state.ary : \
(tc)->state.ptr)

Definition at line 95 of file transcode.c.

◆ TRANSCODING_STATE_EMBED_MAX

#define TRANSCODING_STATE_EMBED_MAX   ((int)sizeof(union rb_transcoding_state_t))

Definition at line 94 of file transcode.c.

◆ TRANSCODING_WRITEBUF

#define TRANSCODING_WRITEBUF (   tc)
Value:
((tc)->transcoder->max_output <= (int)sizeof((tc)->writebuf.ary) ? \
(tc)->writebuf.ary : \
(tc)->writebuf.ptr)

Definition at line 86 of file transcode.c.

◆ TRANSCODING_WRITEBUF_SIZE

#define TRANSCODING_WRITEBUF_SIZE (   tc)
Value:
((tc)->transcoder->max_output <= (int)sizeof((tc)->writebuf.ary) ? \
sizeof((tc)->writebuf.ary) : \
(size_t)(tc)->transcoder->max_output)

Definition at line 90 of file transcode.c.

◆ WORD_ADDR

#define WORD_ADDR (   index)    (tr->word_array + INFO2WORDINDEX(index))

◆ writebuf_len

#define writebuf_len   (tc->writebuf_len)

◆ writebuf_off

#define writebuf_off   (tc->writebuf_off)

Typedef Documentation

◆ rb_transcoding

◆ search_path_queue_t

Function Documentation

◆ Init_transcode()

void Init_transcode ( void  )

Definition at line 4411 of file transcode.c.

References st_init_strcasetable().

◆ InitVM_transcode()

void InitVM_transcode ( void  )

◆ rb_declare_transcoder()

void rb_declare_transcoder ( const char *  enc1,
const char *  enc2,
const char *  lib 
)

Definition at line 231 of file transcode.c.

References rb_eArgError, and rb_raise().

◆ rb_econv_append()

VALUE rb_econv_append ( rb_econv_t ec,
const char *  ss,
long  len,
VALUE  dst,
int  flags 
)

◆ rb_econv_asciicompat_encoding()

const char* rb_econv_asciicompat_encoding ( const char *  ascii_incompat_name)

◆ rb_econv_binmode()

void rb_econv_binmode ( rb_econv_t ec)

◆ rb_econv_check_error()

void rb_econv_check_error ( rb_econv_t ec)

Definition at line 4231 of file transcode.c.

Referenced by rb_econv_append().

◆ rb_econv_close()

void rb_econv_close ( rb_econv_t ec)

◆ rb_econv_convert()

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 
)

Definition at line 1442 of file transcode.c.

References rb_econv_t::started.

Referenced by rb_econv_append().

◆ rb_econv_decorate_at_first()

int rb_econv_decorate_at_first ( rb_econv_t ec,
const char *  decorator_name 
)

Definition at line 1905 of file transcode.c.

References rb_econv_t::num_trans.

◆ rb_econv_decorate_at_last()

int rb_econv_decorate_at_last ( rb_econv_t ec,
const char *  decorator_name 
)

Definition at line 1922 of file transcode.c.

References rb_econv_t::num_trans.

◆ rb_econv_encoding_to_insert_output()

const char* rb_econv_encoding_to_insert_output ( rb_econv_t ec)

◆ rb_econv_has_convpath_p()

int rb_econv_has_convpath_p ( const char *  from_encoding,
const char *  to_encoding 
)

Definition at line 3172 of file transcode.c.

References Qnil.

◆ rb_econv_insert_output()

int rb_econv_insert_output ( rb_econv_t ec,
const unsigned char *  str,
size_t  len,
const char *  str_encoding 
)

◆ rb_econv_make_exception()

VALUE rb_econv_make_exception ( rb_econv_t ec)

Definition at line 4225 of file transcode.c.

◆ rb_econv_memsize()

size_t rb_econv_memsize ( rb_econv_t ec)

◆ rb_econv_open()

rb_econv_t* rb_econv_open ( const char *  sname,
const char *  dname,
int  ecflags 
)

Definition at line 1063 of file transcode.c.

References MAX_ECFLAGS_DECORATORS.

◆ rb_econv_open_exc()

VALUE rb_econv_open_exc ( const char *  sname,
const char *  dname,
int  ecflags 
)

Definition at line 2033 of file transcode.c.

References rb_str_new_cstr().

◆ rb_econv_open_opts()

rb_econv_t* rb_econv_open_opts ( const char *  source_encoding,
const char *  destination_encoding,
int  ecflags,
VALUE  opthash 
)

Definition at line 2575 of file transcode.c.

References NIL_P, OBJ_FROZEN, Qnil, rb_bug(), rb_hash_aref(), RB_TYPE_P, and T_HASH.

◆ rb_econv_prepare_options()

int rb_econv_prepare_options ( VALUE  opthash,
VALUE opts,
int  ecflags 
)

Definition at line 2524 of file transcode.c.

References NIL_P, and Qnil.

Referenced by rb_econv_prepare_opts().

◆ rb_econv_prepare_opts()

int rb_econv_prepare_opts ( VALUE  opthash,
VALUE opts 
)

Definition at line 2569 of file transcode.c.

References rb_econv_prepare_options().

◆ rb_econv_putback()

void rb_econv_putback ( rb_econv_t ec,
unsigned char *  p,
int  n 
)

◆ rb_econv_putbackable()

int rb_econv_putbackable ( rb_econv_t ec)

◆ rb_econv_set_replacement()

int rb_econv_set_replacement ( rb_econv_t ec,
const unsigned char *  str,
size_t  len,
const char *  encname 
)

Definition at line 2195 of file transcode.c.

References encoding_equal, len, MEMCPY, rb_econv_encoding_to_insert_output(), and xmalloc.

◆ rb_econv_str_append()

VALUE rb_econv_str_append ( rb_econv_t ec,
VALUE  src,
VALUE  dst,
int  flags 
)

Definition at line 1862 of file transcode.c.

References rb_econv_substr_append(), and RSTRING_LEN.

◆ rb_econv_str_convert()

VALUE rb_econv_str_convert ( rb_econv_t ec,
VALUE  src,
int  flags 
)

Definition at line 1874 of file transcode.c.

References Qnil, rb_econv_substr_append(), and RSTRING_LEN.

◆ rb_econv_substr_append()

VALUE rb_econv_substr_append ( rb_econv_t ec,
VALUE  src,
long  off,
long  len,
VALUE  dst,
int  flags 
)

◆ rb_econv_substr_convert()

VALUE rb_econv_substr_convert ( rb_econv_t ec,
VALUE  src,
long  byteoff,
long  bytesize,
int  flags 
)

Definition at line 1868 of file transcode.c.

References Qnil, and rb_econv_substr_append().

◆ rb_register_transcoder()

void rb_register_transcoder ( const rb_transcoder tr)

Definition at line 203 of file transcode.c.

References rb_transcoder::dst_encoding, and rb_transcoder::src_encoding.

◆ rb_str_encode()

VALUE rb_str_encode ( VALUE  str,
VALUE  to,
int  ecflags,
VALUE  ecopts 
)

Definition at line 2884 of file transcode.c.

Referenced by rb_str_ellipsize().

Variable Documentation

◆ rb_cEncodingConverter

VALUE rb_cEncodingConverter

Definition at line 23 of file transcode.c.

◆ rb_eConverterNotFoundError

VALUE rb_eConverterNotFoundError

Definition at line 21 of file transcode.c.

Referenced by InitVM_transcode().

◆ rb_eInvalidByteSequenceError

VALUE rb_eInvalidByteSequenceError

Definition at line 20 of file transcode.c.

Referenced by InitVM_transcode().

◆ rb_eUndefinedConversionError

VALUE rb_eUndefinedConversionError

Definition at line 19 of file transcode.c.

Referenced by InitVM_transcode().