The ifx_gl_mbsprev() function

The ifx_gl_mbsprev() function returns the previous multibyte character in a multibyte string.

Syntax

#include <ifxgls.h>
...
gl_mchar_t *ifx_gl_mbsprev(mbs_start, mb)
        gl_mchar_t *mbs_start;
        gl_mchar_t *mb;
mbs_start
A pointer to beginning of the multibyte string.
mb
A pointer to the current multibyte character in the multibyte string.
Valid in client application Valid in DataBlade® UDR
Yes Yes

Usage

The ifx_gl_mbsprev() function returns a pointer to the multibyte character before mb in a multibyte-character string. This function is typically used to transform the single-byte reverse-traversal loop to a multibyte loop. For example, suppose you have the following single-byte loop:
sb = sb0 + strlen(sb0);
for ( sb--; sb >= sb0; sb-- )
    /* Process single-byte character */
The following code fragment traverses the string with the ifx_gl_mbsprev() function instead of decrementing the pointer of the single-byte loop:
mb = mbs_start + strlen(mbs_start);
for ( mb = ifx_gl_mbsprev(mbs_start, mb) ; mb >= mbs_start;
    mb = ifx_gl_mbsprev(mbs_start, mb) )
    /* Process multibyte character */

Return values

gl_mchar_t *
A pointer to the first byte of the multibyte character immediately before mb.
NULL
The function was not successful, and the error number is set to indicate the cause. See the Errors section.

Errors

If an error occurred, this function returns NULL and sets the ifx_gl_lc_errno() error number to one of the following values.
IFX_GL_EILSEQ
The *mb character or a character between mbs_start and mb is not a valid multibyte character.
IFX_GL_EINVPTR
The mb value is less than or equal to mbs_start.
IFX_GL_EINVAL
The function cannot determine whether the character before mb is a valid multibyte character because it would need to read beyond mb.