Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Typedefs | Functions | Variables
transcode.c File Reference
`#include "ruby/encoding.h"`
`#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_t * | rb_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_t * | rb_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_cEncodingConverter

## Macro Definition Documentation

## ◆ BL_ACTION

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

## ◆ BL_BASE

#define BL_BASE BYTE_ADDR(BYTE_LOOKUP_BASE(WORD_ADDR(next_table)))

## ◆ BL_INFO

#define BL_INFO WORD_ADDR(BYTE_LOOKUP_INFO(WORD_ADDR(next_table)))

## ◆ 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 153 of file transcode.c.

## ◆ ENABLE_ECONV_NEWLINE_OPTION

#define ENABLE_ECONV_NEWLINE_OPTION 1

Definition at line 17 of file transcode.c.

## ◆ encoding_equal

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

Definition at line 240 of file transcode.c.

## ◆ hash_fallback

#define hash_fallback rb_hash_aref

Definition at line 2227 of file transcode.c.

## ◆ MAX_ECFLAGS_DECORATORS

#define MAX_ECFLAGS_DECORATORS 32

Definition at line 1010 of file transcode.c.

## ◆ 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)

## ◆ SUSPEND_AFTER_OUTPUT

#define SUSPEND_AFTER_OUTPUT | ( |  | num | ) |

Value:
if ((opt & ECONV_AFTER_OUTPUT) && *out_pos != out_p) { \
SUSPEND(econv_after_output, num); \
}

## ◆ SUSPEND_OBUF

#define SUSPEND_OBUF | ( |  | num | ) |

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

## ◆ 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 83 of file transcode.c.

## ◆ TRANSCODING_STATE

#define TRANSCODING_STATE | ( |  | tc | ) |

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

Definition at line 96 of file transcode.c.

## ◆ TRANSCODING_STATE_EMBED_MAX

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

Definition at line 95 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 87 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 91 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

typedef struct rb_transcoding rb_transcoding

## ◆ search_path_queue_t

typedef struct search_path_queue_tag search_path_queue_t

## Function Documentation

## ◆ Init_transcode()

void Init_transcode | ( | void |  | ) |

Definition at line 4403 of file transcode.c.

## ◆ InitVM_transcode()

void InitVM_transcode | ( | void |  | ) |

Definition at line 4440 of file transcode.c.

## ◆ rb_declare_transcoder()

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

Definition at line 232 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
| ) |  |

Definition at line 1795 of file transcode.c.

References rb_econv_t::destination_encoding, dp, econv_destination_buffer_full, rb_econv_t::last_tc, len, long, LONG_MAX, rb_transcoder::max_output, NIL_P, rb_eArgError, rb_econv_check_error(), rb_econv_convert(), rb_enc_associate(), rb_raise(), rb_str_buf_new(), rb_str_capacity(), rb_str_resize(), rb_str_set_len(), RSTRING_LEN, RSTRING_PTR, and rb_transcoding::transcoder.

Referenced by rb_econv_substr_append().

## ◆ rb_econv_asciicompat_encoding()

const char* rb_econv_asciicompat_encoding | ( | const char * | ascii_incompat_name | ) |

Definition at line 1768 of file transcode.c.

References st_lookup(), and v.

## ◆ rb_econv_binmode()

void rb_econv_binmode | ( | rb_econv_t * | ec | ) |

Definition at line 1924 of file transcode.c.

References ECONV_CR_NEWLINE_DECORATOR, ECONV_CRLF_NEWLINE_DECORATOR, ECONV_NEWLINE_DECORATOR_MASK, ECONV_UNIVERSAL_NEWLINE_DECORATOR, and rb_econv_t::flags.

Referenced by rb_io_binmode().

## ◆ rb_econv_check_error()

void rb_econv_check_error | ( | rb_econv_t * | ec | ) |

Definition at line 4223 of file transcode.c.

References exc.

Referenced by rb_econv_append().

## ◆ rb_econv_close()

void rb_econv_close | ( | rb_econv_t * | ec | ) |

Definition at line 1684 of file transcode.c.

References i, rb_econv_t::num_trans, rb_econv_t::replacement_allocated, rb_econv_t::replacement_str, and xfree.

## ◆ 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 1428 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 1890 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 1907 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 | ) |

Definition at line 1485 of file transcode.c.

References asciicompat_encoder, rb_econv_t::last_tc, NULL, and rb_transcoding::transcoder.

Referenced by rb_econv_insert_output(), and rb_econv_set_replacement().

## ◆ rb_econv_has_convpath_p()

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

Definition at line 3166 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
| ) |  |

Definition at line 1569 of file transcode.c.

References encoding_equal, len, NULL, rb_econv_encoding_to_insert_output(), rb_econv_t::started, and str.

## ◆ rb_econv_make_exception()

VALUE rb_econv_make_exception | ( | rb_econv_t * | ec | ) |

Definition at line 4217 of file transcode.c.

## ◆ rb_econv_memsize()

size_t rb_econv_memsize | ( | rb_econv_t * | ec | ) |

Definition at line 1702 of file transcode.c.

References i, rb_econv_t::num_trans, rb_econv_t::replacement_allocated, rb_econv_t::replacement_len, and size.

Referenced by rb_io_memsize().

## ◆ rb_econv_open()

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

Definition at line 1051 of file transcode.c.

References i, and MAX_ECFLAGS_DECORATORS.

## ◆ rb_econv_open_exc()

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

Definition at line 2018 of file transcode.c.

References exc, and 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 2560 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 2509 of file transcode.c.

References NIL_P, Qnil, and v.

Referenced by rb_econv_prepare_opts().

## ◆ rb_econv_prepare_opts()

int rb_econv_prepare_opts | ( | VALUE | opthash,
|  | VALUE * | opts
| ) |  |

Definition at line 2554 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
| ) |  |

Definition at line 1735 of file transcode.c.

References rb_econv_t::elems, memcpy(), n, rb_econv_t::num_trans, rb_transcoding::readagain_len, rb_transcoding::recognized_len, rb_econv_elem_t::tc, and TRANSCODING_READBUF.

## ◆ rb_econv_putbackable()

int rb_econv_putbackable | ( | rb_econv_t * | ec | ) |

Definition at line 1724 of file transcode.c.

References rb_econv_t::elems, INT_MAX, rb_econv_t::num_trans, rb_transcoding::readagain_len, and rb_econv_elem_t::tc.

## ◆ 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 2180 of file transcode.c.

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

## ◆ rb_econv_str_append()

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

Definition at line 1847 of file transcode.c.

References rb_econv_substr_append(), RSTRING_LEN, and src.

## ◆ rb_econv_str_convert()

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

Definition at line 1859 of file transcode.c.

References Qnil, rb_econv_substr_append(), RSTRING_LEN, and src.

## ◆ rb_econv_substr_append()

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

Definition at line 1838 of file transcode.c.

References len, rb_econv_append(), RB_GC_GUARD, rb_str_new_frozen(), RSTRING_PTR, and src.

Referenced by rb_econv_str_append(), rb_econv_str_convert(), and rb_econv_substr_convert().

## ◆ rb_econv_substr_convert()

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

Definition at line 1853 of file transcode.c.

References Qnil, rb_econv_substr_append(), and src.

## ◆ rb_register_transcoder()

void rb_register_transcoder | ( | const rb_transcoder * | tr | ) |

Definition at line 204 of file transcode.c.

## ◆ rb_str_encode()

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

Definition at line 2869 of file transcode.c.

References argc, argv, and str.

Referenced by rb_str_ellipsize().

## Variable Documentation

## ◆ rb_cEncodingConverter

VALUE rb_cEncodingConverter

Definition at line 24 of file transcode.c.

size_t
long unsigned int size_t
Definition: rb_mjit_min_header-2.7.0.h:666
econv_after_output
@ econv_after_output
Definition: encoding.h:303
ECONV_AFTER_OUTPUT
#define ECONV_AFTER_OUTPUT
Definition: encoding.h:416
econv_destination_buffer_full
@ econv_destination_buffer_full
Definition: encoding.h:300
SUSPEND
#define SUSPEND(ret, num)
TRANSCODING_READBUF
#define TRANSCODING_READBUF(tc)
Definition: transcode.c:83