---
name: "cucul_charset"
section: "3caca"
platform: "linux"
package: "libcucul-dev"
version: "0.99.beta14-1"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/cucul_charset"
---

# cucul\_charset(3caca)

## NAME

libcucul character set conversions -

### Functions

\_\_extern uint32\_t **cucul\_utf8\_to\_utf32** (char const \*, size\_t \*)\
 *Convert a UTF-8 character to UTF-32.*  \_\_extern size\_t **cucul\_utf32\_to\_utf8** (char \*, uint32\_t)\
 *Convert a UTF-32 character to UTF-8.*  \_\_extern uint8\_t **cucul\_utf32\_to\_cp437** (uint32\_t)\
 *Convert a UTF-32 character to CP437.*  \_\_extern uint32\_t **cucul\_cp437\_to\_utf32** (uint8\_t)\
 *Convert a CP437 character to UTF-32.*  \_\_extern char **cucul\_utf32\_to\_ascii** (uint32\_t)\
 *Convert a UTF-32 character to ASCII.*  \_\_extern int **cucul\_utf32\_is\_fullwidth** (uint32\_t)\
 *Tell whether a UTF-32 character is fullwidth.*

## Detailed Description

These functions perform conversions between usual character sets.

## Function Documentation

### \_\_extern uint32\_t cucul\_utf8\_to\_utf32 (char const \* s, size\_t \* bytes)

Convert a UTF-8 character read from a string and return its value in the UTF-32 character set. If the second argument is not null, the total number of read bytes is written in it.

If a null byte was reached before the expected end of the UTF-8 sequence, this function returns zero and the number of read bytes is set to zero.

This function never fails, but its behaviour with illegal UTF-8 sequences is undefined.

**Parameters:**

*s* A string containing the UTF-8 character. \
 *bytes* A pointer to a size\_t to store the number of bytes in the character, or NULL.

**Returns:**

The corresponding UTF-32 character, or zero if the character is incomplete.

Referenced by cucul\_put\_str().

### \_\_extern size\_t cucul\_utf32\_to\_utf8 (char \* buf, uint32\_t ch)

Convert a UTF-32 character read from a string and write its value in the UTF-8 character set into the given buffer.

This function never fails, but its behaviour with illegal UTF-32 characters is undefined.

**Parameters:**

*buf* A pointer to a character buffer where the UTF-8 sequence will be written. \
 *ch* The UTF-32 character.

**Returns:**

The number of bytes written.

### \_\_extern uint8\_t cucul\_utf32\_to\_cp437 (uint32\_t ch)

Convert a UTF-32 character read from a string and return its value in the CP437 character set, or '?' if the character has no equivalent.

This function never fails.

**Parameters:**

*ch* The UTF-32 character.

**Returns:**

The corresponding CP437 character, or '?' if not representable.

### \_\_extern uint32\_t cucul\_cp437\_to\_utf32 (uint8\_t ch)

Convert a CP437 character read from a string and return its value in the UTF-32 character set, or zero if the character is a CP437 control character.

This function never fails.

**Parameters:**

*ch* The CP437 character.

**Returns:**

The corresponding UTF-32 character, or zero if not representable.

### \_\_extern char cucul\_utf32\_to\_ascii (uint32\_t ch)

Convert a UTF-32 character into an ASCII character. When no equivalent exists, a graphically close equivalent is sought.

This function never fails, but its behaviour with illegal UTF-32 characters is undefined.

**Parameters:**

*ch* The UTF-32 character.

**Returns:**

The corresponding ASCII character, or a graphically close equivalent if found, or '?' if not representable.

### \_\_extern int cucul\_utf32\_is\_fullwidth (uint32\_t ch)

Check whether the given UTF-32 character should be printed at twice the normal width (fullwidth characters). If the character is unknown or if its status cannot be decided, it is treated as a standard-width character.

This function never fails.

**Parameters:**

*ch* The UTF-32 character.

**Returns:**

1 if the character is fullwidth, 0 otherwise.

Referenced by cucul\_put\_char(), and cucul\_put\_str().
