BSON_UNICHAR_T(3)

✨ BSON_UNICHAR_T(3) ✨

okay so bestie, welcome to libbson's little corner of the manual devoted to one (1) very iconic thing: the Unicode Character Abstraction. yes that's the whole vibe. let's get into it πŸ’…


🌸 SYNOPSIS 🌸

typedef uint32_t bson_unichar_t;

that's it. that's the girl. one typedef and she's already serving πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, bson_unichar_t is literally an abstraction on a single unicode character. it's the 32-bit representation of a character β€” yes, 32-bit, she's not doing the small-bit thing, she's doing the whole bit thing πŸ’–

and here's the part where you gotta pay attention: since UTF-8 can contain multi-byte characters, this is the type you should be using when you're iterating through UTF-8 text. like, do not come in there poking at single bytes and expecting it to work, that's not the move. bson_unichar_t is the main character here, no cap 🌈

lowkey important: multi-byte characters are exactly why this abstraction exists. use it when iterating UTF-8 text, fr fr.

πŸŽ€ EXAMPLE πŸŽ€

here's a cute little function that prints out the numeric value of every character in a string, bestie:

static void
print_each_char (const char *str)
{
   bson_unichar_t c;

   for (; *str; str = bson_utf8_next_char (str)) {
      c = bson_utf8_get_char (str);
      printf ("The numberic value is %u.\n", (unsigned) c);
   }
}

see how it walks the string with bson_utf8_next_char and pulls the character with bson_utf8_get_char? that's the whole pattern, and honestly? ate. πŸ’… (and yes, the format string in the original really does say numberic β€” we keep it exactly as-is, iconic typo and all, not me fixing it, never me fixing it πŸ™ˆ)


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc


2009-present, MongoDB, Inc.


and that's the page! 🫢 cute little sign-off for you: this was libbson 2.5.6, dated Oct 09, 2026 β€” so go forth, iterate your UTF-8 like a legend, and remember: 32 bits of unicode excellence, periodt πŸ’œπŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from