---
name: "bson_utf8"
section: "3"
platform: "linux"
package: "libbson-doc"
version: "1.23.1-1+deb12u3"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/bson_utf8"
---

# bson\_utf8(3)

UTF-8

## NAME

bson\_utf8 - UTF-8

## ENCODING

Libbson expects that you are always working with UTF-8 encoded text. Anything else is **invalid API use**.

If you should need to walk through UTF-8 sequences, you can use the various UTF-8 helper functions distributed with Libbson.

## VALIDATING A UTF-8 SEQUENCE

To validate the string contained in **my\_string**, use the following. You may pass **-1** for the string length if you know the string is NULL-terminated.

```
if (!bson_utf8_validate (my_string, -1, false)) {
   printf ("Validation failed.\n");
}
```

If **my\_string** has NULL bytes within the string, you must provide the string length. Use the following format. Notice the **true** at the end indicating **\\0** is allowed.

```
if (!bson_utf8_validate (my_string, my_string_len, true)) {
   printf ("Validation failed.\n");
}
```

For more information see the API reference for *bson\_utf8\_validate()*.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2017-present, MongoDB, Inc
