Rudiments
Public Member Functions | Static Public Member Functions | List of all members
iconvert Class Reference

Inherits object.

Public Member Functions

 iconvert ()
 
 iconvert (iconvert &i)
 
iconvertoperator= (iconvert &i)
 
virtual ~iconvert ()
 
void setFromEncoding (const char *fromencoding)
 
const char * getFromEncoding ()
 
void setToEncoding (const char *fromencoding)
 
const char * getToEncoding ()
 
void setFromBuffer (const byte_t *buffer)
 
const byte_t * getFromBuffer ()
 
void setFromBufferSize (size_t buffersize)
 
size_t getFromBufferSize ()
 
void setToBuffer (byte_t *buffer)
 
byte_t * getToBuffer ()
 
void setToBufferSize (size_t buffersize)
 
size_t getToBufferSize ()
 
bool convert ()
 
const byte_t * getFromBufferPosition ()
 
size_t getFromBufferRemaining ()
 
const byte_t * getToBufferPosition ()
 
size_t getToBufferRemaining ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Static Public Member Functions

static uint16_t getMaxMultiByteSize ()
 
static bool getNeedsMutex ()
 

Detailed Description

The iconvert class implements character encoding converter.

Constructor & Destructor Documentation

◆ iconvert() [1/2]

iconvert::iconvert ( )

Creates a new instance of the iconvert class.

◆ iconvert() [2/2]

iconvert::iconvert ( iconvert i)

Crates an instance of the iconvert class with the same from and to encodings as "i".

◆ ~iconvert()

virtual iconvert::~iconvert ( )
virtual

Deletes this instance of the iconvert class.

Member Function Documentation

◆ convert()

bool iconvert::convert ( )

Processes characters from the "from buffer", converting them from the "from encoding" to the "to encoding" and writing the converted characters to the "to buffer".

Sets the "from buffer position" to a pointer to the first byte of the "from buffer" after the last character that was processed. Sets the "from buffer remaining" to the number of bytes in the "from buffer" that were not processed.

Sets the "to buffer position" to a pointer to the first byte in the "to buffer" after the last character that was written. Sets the "to buffer remaining" to the number of bytes in the "to buffer" that were not written to.

Returns true on successful conversion.

Returns false if one of the following errors occur.

If conversion from the "from encoding" to the "to encoding" isn't supported then the error number will be set to ENOSYS.

If the "to buffer size" isn't sufficient to store the converted characters (eg. because we're converting to a multi-byte encoding and there aren't enough bytes to store the multi-byte character) then the error number will be set to E2BIG.

If an invalid multibyte sequence was encountered in the "from buffer" then the error number will be set to EILSEQ.

If an incomplete multibyte sequence was encountered in the "from buffer" then the error number will be set to EINVAL.

In each of these error cases, the "from buffer position" will be set to the "from buffer" and the "from buffer remaining" will be set to the "from buffer size". The "to buffer position" will be set to the "to buffer" and the "to buffer remaining" will be set to the "to buffer size".

◆ getFromBuffer()

const byte_t* iconvert::getFromBuffer ( )

Returns the "from buffer" as previously set by setFromBuffer(), or as set by a call to convert().

◆ getFromBufferPosition()

const byte_t* iconvert::getFromBufferPosition ( )

Returns the "from buffer position" - the position in the "from buffer" set by a previous call to convert().

◆ getFromBufferRemaining()

size_t iconvert::getFromBufferRemaining ( )

Returns the "from buffer remaining" - the number of bytes remaining in "from buffer", as set by a previous call to convert().

◆ getFromBufferSize()

size_t iconvert::getFromBufferSize ( )

Returns the number of bytes in the "from buffer", as set by a previous call to setFromBufferSize().

◆ getFromEncoding()

const char* iconvert::getFromEncoding ( )

Returns the "from encoding" of the instance as set by a previous call to setFromEncoding(), the copy constructor, or = operator.

◆ getMaxMultiByteSize()

static uint16_t iconvert::getMaxMultiByteSize ( )
static

Returns the maximum number of bytes that a multibyte character can contain.

Can be used, for example, when sizing the "to buffer", when converting to a multibyte encoding.

◆ getNeedsMutex()

static bool iconvert::getNeedsMutex ( )
static

Returns true if convert() needs to be protected with a mutex (eg. because it might need to use non-reentrant functions) or false if it does not (eg. because it only uses reentrant functions).

◆ getToBuffer()

byte_t* iconvert::getToBuffer ( )

Returns the "to buffer" as set by a previous call to setToBuffer().

◆ getToBufferPosition()

const byte_t* iconvert::getToBufferPosition ( )

Returns the "to buffer position" - the position in the "to buffer" set by a previous call to convert().

◆ getToBufferRemaining()

size_t iconvert::getToBufferRemaining ( )

Returns the "to buffer remaining" - the number of bytes remaining in "to buffer", as set by a previous call to convert().

◆ getToBufferSize()

size_t iconvert::getToBufferSize ( )

Returns the number of bytes in the "to buffer" as set by a previous call to setToBufferSize().

◆ getToEncoding()

const char* iconvert::getToEncoding ( )

Returns the "to encoding" of the instance as set by a previous call to setToEncoding(), the copy constructor, or = operator.

◆ operator=()

iconvert& iconvert::operator= ( iconvert i)

Closes this instance of the inconvert class and sets its from and to encodings to the same as "i".

◆ setFromBuffer()

void iconvert::setFromBuffer ( const byte_t *  buffer)

Sets the "from buffer" - the buffer that characters will be read from during the call to convert(). Specifically, "buffer" should be a pointer to the first byte that will be read when convert() is called.

◆ setFromBufferSize()

void iconvert::setFromBufferSize ( size_t  buffersize)

Sets the number of bytes in the "from buffer". The call to convert() won't attempt to process more bytes than this.

◆ setFromEncoding()

void iconvert::setFromEncoding ( const char *  fromencoding)

Sets the "from encoding" of the instance. This is the encoding that characters in the "from buffer" are expected to have.

◆ setToBuffer()

void iconvert::setToBuffer ( byte_t *  buffer)

Sets the "to buffer" - the buffer that characters will be written to during a call to convert().

◆ setToBufferSize()

void iconvert::setToBufferSize ( size_t  buffersize)

Sets the number of bytes in the "to buffer". The call to convert() won't attempt to write more bytes than this.

◆ setToEncoding()

void iconvert::setToEncoding ( const char *  fromencoding)

Sets the "to encoding" of the instance. This is the encoding that characters in the "to buffer" are expected to have.