The ifx_gl_mbslen() function
The ifx_gl_mbslen() function determines the number of characters in a multibyte-character string.
Syntax
#include <ifxgls.h>
...
int ifx_gl_mbslen(mbs, mbs_byte_length)
gl_mchar_t *mbs;
int mbs_byte_length;
- mbs
- A pointer to the multibyte-character string whose length the function determines.
- mbs_byte_length
- The integer number of bytes in the mbs string. If mbs_byte_length is the value IFX_GL_NULL, the function assumes that mbs is a null-terminated string.
Valid in client application | Valid in DataBlade® UDR |
---|---|
Yes | Yes |
Usage
The ifx_gl_mbslen() function returns the number of characters (not bytes) in the string mbs, not including any terminating null character. The length that ifx_gl_mbslen() returns includes any trailing white space. The trailing-space characters are all characters that the blank character class of the current locale defines. Use the ifx_gl_mbntslen() function if you want the length without trailing white space.
For example, the following call
to ifx_gl_mbslen() returns a value of 12 (where
A1A2 is the multibyte character of 2 bytes,
B1B2B3 is the multibyte character
of 3 bytes, and E1 is the multibyte character of 1 byte,
and each s represents a single-byte horizontal white space
character):
ifx_gl_mbslen("A1A2B1B2B3scdsE1sssss", mbs_byte_length)
Use the ifx_gl_mbsntslen() or ifx_gl_mbsntsbytes() function if you want the length without trailing white space.
Return values
- >=0
- The number of characters in the mbs string, not including any null terminator but including any trailing white space.
- -1
- 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 -1 and sets the ifx_gl_lc_errno() error
number to one of the following values.
- IFX_GL_PARAMERR
- The mbs_byte_length is not equal to IFX_GL_NULL and is not greater than or equal to 0.
- IFX_GL_EILSEQ
- The *mbs value contains an invalid multibyte character.
- IFX_GL_EINVAL
- The function cannot determine whether the last character of mbs is a valid multibyte character because it would need to read more than mbs_byte_length bytes from mbs.