1 #ifndef RUBY_INTERNAL_ENCODING_TRANSCODE_H
2 #define RUBY_INTERNAL_ENCODING_TRANSCODE_H
198 const unsigned char **source_buffer_ptr,
const unsigned char *source_buffer_end,
199 unsigned char **destination_buffer_ptr,
unsigned char *destination_buffer_end,
286 const unsigned char *str,
size_t len,
const char *str_encoding);
516 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
522 #define ECONV_ERROR_HANDLER_MASK RUBY_ECONV_ERROR_HANDLER_MASK
523 #define ECONV_INVALID_MASK RUBY_ECONV_INVALID_MASK
524 #define ECONV_INVALID_REPLACE RUBY_ECONV_INVALID_REPLACE
525 #define ECONV_UNDEF_MASK RUBY_ECONV_UNDEF_MASK
526 #define ECONV_UNDEF_REPLACE RUBY_ECONV_UNDEF_REPLACE
527 #define ECONV_UNDEF_HEX_CHARREF RUBY_ECONV_UNDEF_HEX_CHARREF
528 #define ECONV_DECORATOR_MASK RUBY_ECONV_DECORATOR_MASK
529 #define ECONV_NEWLINE_DECORATOR_MASK RUBY_ECONV_NEWLINE_DECORATOR_MASK
530 #define ECONV_NEWLINE_DECORATOR_READ_MASK RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK
531 #define ECONV_NEWLINE_DECORATOR_WRITE_MASK RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK
532 #define ECONV_UNIVERSAL_NEWLINE_DECORATOR RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR
533 #define ECONV_CRLF_NEWLINE_DECORATOR RUBY_ECONV_CRLF_NEWLINE_DECORATOR
534 #define ECONV_CR_NEWLINE_DECORATOR RUBY_ECONV_CR_NEWLINE_DECORATOR
535 #define ECONV_LF_NEWLINE_DECORATOR RUBY_ECONV_LF_NEWLINE_DECORATOR
536 #define ECONV_XML_TEXT_DECORATOR RUBY_ECONV_XML_TEXT_DECORATOR
537 #define ECONV_XML_ATTR_CONTENT_DECORATOR RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR
538 #define ECONV_STATEFUL_DECORATOR_MASK RUBY_ECONV_STATEFUL_DECORATOR_MASK
539 #define ECONV_XML_ATTR_QUOTE_DECORATOR RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR
540 #define ECONV_DEFAULT_NEWLINE_DECORATOR RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR
554 #define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT
555 #define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
@ RUBY_ECONV_STATEFUL_DECORATOR_MASK
(Unclear; seems unused).
@ RUBY_ECONV_CRLF_NEWLINE_DECORATOR
CR to CRLF conversion shall happen.
@ RUBY_ECONV_AFTER_OUTPUT
Instructs the converter to stop after output.
@ RUBY_ECONV_FLAGS_PLACEHOLDER
Placeholder (not used)
@ RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK
(Unclear; seems unused).
@ RUBY_ECONV_LF_NEWLINE_DECORATOR
CRLF to LF conversion shall happen.
@ RUBY_ECONV_ERROR_HANDLER_MASK
Mask for error handling related bits.
@ RUBY_ECONV_UNDEF_MASK
Special handling of undefined conversion are there.
@ RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR
Texts shall be AttrValue escaped.
@ RUBY_ECONV_INVALID_REPLACE
Invalid sequences shall be replaced.
@ RUBY_ECONV_XML_TEXT_DECORATOR
Texts shall be XML-escaped.
@ RUBY_ECONV_NEWLINE_DECORATOR_MASK
Newline converters are there.
@ RUBY_ECONV_UNDEF_HEX_CHARREF
Undefined characters shall be escaped.
@ RUBY_ECONV_PARTIAL_INPUT
Indicates the input is a part of much larger one.
@ RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR
Universal newline mode.
@ RUBY_ECONV_INVALID_MASK
Special handling of invalid sequences are there.
@ RUBY_ECONV_UNDEF_REPLACE
Undefined characters shall be replaced.
@ RUBY_ECONV_DECORATOR_MASK
Decorators are there.
@ RUBY_ECONV_XML_ATTR_QUOTE_DECORATOR
Texts shall be AttrValue escaped.
@ RUBY_ECONV_DEFAULT_NEWLINE_DECORATOR
Newline decorator's default.
@ RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK
(Unclear; seems unused).
@ RUBY_ECONV_CR_NEWLINE_DECORATOR
CRLF to CR conversion shall happen.
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags)
Identical to rb_econv_prepare_opts(), except it additionally takes the initial value of flags.
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags)
Creates a rb_eConverterNotFoundError exception object (but does not raise).
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts)
Splits a keyword arguments hash (that for instance String#encode took) into a set of enum ruby_econv_...
rb_econv_result_t rb_econv_convert(rb_econv_t *ec, const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end, unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end, int flags)
Converts a string from an encoding to another.
rb_econv_result_t
return value of rb_econv_convert()
@ econv_incomplete_input
The conversion stopped in middle of reading a character, possibly due to a partial read of a socket e...
@ econv_finished
The conversion stopped after converting everything.
@ econv_undefined_conversion
The conversion stopped when it found a character in the input which cannot be representable in the ou...
@ econv_after_output
The conversion stopped after writing something to somewhere, before reading everything.
@ econv_source_buffer_empty
The conversion stopped because there is no input.
@ econv_destination_buffer_full
The conversion stopped because there is no destination.
@ econv_invalid_byte_sequence
The conversion stopped when it found an invalid sequence.
int rb_econv_putbackable(rb_econv_t *ec)
Queries if rb_econv_putback() makes sense, i.e.
int rb_econv_has_convpath_p(const char *from_encoding, const char *to_encoding)
Queries if there is more than one way to convert between the passed two encodings.
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags)
Identical to rb_econv_str_convert(), except it appends the conversion result to the additionally pass...
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags)
Identical to rb_econv_str_append(), except it appends only a part of the passed string with conversio...
int rb_econv_insert_output(rb_econv_t *ec, const unsigned char *str, size_t len, const char *str_encoding)
Appends the passed string to the passed converter's output buffer.
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
Identical to rb_econv_convert(), except it takes Ruby's string instead of C's pointer.
int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name)
Identical to rb_econv_decorate_at_first(), except it adds to the opposite direction.
void rb_econv_binmode(rb_econv_t *ec)
This badly named function does not set the destination encoding to binary, but instead just nullifies...
int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name)
"Decorate"s a converter.
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
Converts the contents of the passed string from its encoding to the passed one.
VALUE rb_econv_make_exception(rb_econv_t *ec)
This function makes sense right after rb_econv_convert() returns.
void rb_econv_check_error(rb_econv_t *ec)
This is a rb_econv_make_exception() + rb_exc_raise() combo.
const char * rb_econv_asciicompat_encoding(const char *encname)
Queries the passed encoding's corresponding ASCII compatible encoding.
VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags)
Identical to rb_econv_str_convert(), except it converts only a part of the passed string.
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
Identical to rb_econv_open(), except it additionally takes a hash of optional strings.
void rb_econv_close(rb_econv_t *ec)
Destructs a converter.
VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags)
Converts the passed C's pointer according to the passed converter, then append the conversion result ...
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n)
Puts back the bytes.
int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname)
Assigns the replacement string.
rb_econv_t * rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags)
Creates a new instance of struct rb_econv_t.
ruby_econv_flag_type
This enum is kind of omnibus.
const char * rb_econv_encoding_to_insert_output(rb_econv_t *ec)
Queries an encoding name which best suits for rb_econv_insert_output()'s last parameter.
int len
Length of the buffer.
uintptr_t VALUE
Type that represents a Ruby object.