tuklib_mbstr_width.c File Reference

Calculate width of a multibyte string. More...

`#include "tuklib_mbstr.h"`
`#include <string.h>`

## Functions

size_t | tuklib_mbstr_width (const char *str, size_t *bytes)
| Get the number of columns needed for the multibyte string. More...

## Detailed Description

Calculate width of a multibyte string.

## Function Documentation

## tuklib_mbstr_width()

size_t tuklib_mbstr_width | ( | const char * | str,
|  | size_t * | bytes
| ) |  |

Get the number of columns needed for the multibyte string.

This is somewhat similar to wcswidth() but works on multibyte strings.

Parameters

  str | String whose width is to be calculated. If the current locale uses a multibyte character set that has shift states, the string must begin and end in the initial shift state.
  bytes | If this is not NULL, *bytes is set to the value returned by strlen(str) (even if an error occurs when calculating the width).

Returns
  On success, the number of columns needed to display the string e.g. in a terminal emulator is returned. On error, (size_t)-1 is returned. Possible errors include invalid, partial, or non-printable multibyte character in str, or that str doesn't end in the initial shift state.