The m17n Library: MConverter Struct Reference

# MConverter Struct Reference
[Code Conversion]

Structure to be used in code conversion. More...

## Data Fields
int | lenient
int | last_block
unsigned | at_most
int | nchars
int | nbytes
enum MConversionResult | result
union {
void * ptr
double dbl
char c [256]
} | status
void * | internal_info

## Detailed Description

Structure to be used in code conversion.

Structure to be used in code conversion. The first three members are to control the conversion.

## Field Documentation

int MConverter::lenient

Set the value to nonzero if the conversion should be lenient. By default, the conversion is strict (i.e. not lenient).

If the conversion is strict, the converter stops at the first invalid byte (on decoding) or at the first character not supported by the coding system (on encoding). If this happens, `MConverter->result` is set to `MCONVERSION_RESULT_INVALID_BYTE` or `MCONVERSION_RESULT_INVALID_CHAR` accordingly.

If the conversion is lenient, on decoding, an invalid byte is kept per se, and on encoding, an invalid character is replaced with "<U+XXXX>" (if the character is a Unicode character) or with "<M+XXXXXX>" (otherwise).

int MConverter::last_block

Set the value to nonzero before decoding or encoding the last block of the byte sequence or the character sequence respectively. The value influences the conversion as below.

On decoding, in the case that the last few bytes are too short to form a valid byte sequence:

If the value is nonzero, the conversion terminates by error (MCONVERSION_RESULT_INVALID_BYTE) at the first byte of the sequence.

If the value is zero, the conversion terminates successfully. Those bytes are stored in the converter as carryover and are prepended to the byte sequence of the further conversion.

On encoding, in the case that the coding system is context dependent:

If the value is nonzero, the conversion may produce a byte sequence at the end to reset the context to the initial state even if the source characters are zero.

If the value is zero, the conversion never produce such a byte sequence at the end.

unsigned MConverter::at_most

If the value is nonzero, it specifies at most how many characters to convert.

int MConverter::nchars

The following three members are to report the result of the conversion.

Number of characters most recently decoded or encoded.

int MConverter::nbytes

Number of bytes recently decoded or encoded.

enum MConversionResult MConverter::result

Result code of the conversion.

void* MConverter::ptr

double MConverter::dbl

char MConverter::c[256]

union { ... } MConverter::status

Various information about the status of code conversion. The contents depend on the type of coding system. It is assured that `status` is aligned so that any type of casting is safe and at least 256 bytes of memory space can be used.

void* MConverter::internal_info

This member is for internally use only. An application program should never touch it.