BSON_UTF8_VALIDATE(3)

πŸ’… BSON_UTF8_VALIDATE(3) πŸ’…

okay so bestie, you're in libbson land and you need to know if a string is actually valid UTF-8 before you go handing it to anything important. this little function is your vibe check for bytes. she's not flashy, she just does her job and she does it flawlessly. 🧚✨


✨ SYNOPSIS ✨

bool
bson_utf8_validate (const char *utf8, size_t utf8_len, bool allow_null);

🫢 PARAMETERS 🫢

  • utf8 β€” the string you want to verify. like, the actual thing you're suspicious of. hand her over. πŸ”
  • utf8_len β€” how long utf8 is, in bytes (not characters, bestie, bytes, this is important, iykyk). πŸ“
  • allow_null β€” a bool that says whether embedded \0 bytes are allowed. true = yeah babes, nulls welcome. false = absolutely not. 🚫

🌸 DESCRIPTION 🌸

so what she does is: she validates that the content inside utf8 is valid UTF-8 β€” and not just by vibe, by the RFC 3629 standard, which is the real one, no cap. πŸ“œπŸ‘‘

and if allow_null is true, then embedded NULL bytes are allowed too (\0). literally she'll just let them vibe there. if it's false... those nulls are not invited to the party. πŸ’€

fr fr, this is the standard-compliance check, not a "close enough" check. she read the whole RFC. she took notes. she's that girl. πŸŽ€

⭐ RETURNS ⭐

true if utf8 contains valid UTF-8. that's it. that's the whole answer. slay. πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” iconic behavior, honestly. 🫑


2009-present, MongoDB, Inc. β€” a whole era, and she's still serving. 🌈


okay that's the whole page bestie!! huge thank you to the fine people at libbson version 2.5.6, dated Oct 09, 2026 β€” go validate some bytes, be safe, and remember: it's bytes, not characters. mwah πŸ’‹βœ¨πŸ’œ

πŸ“¦ where this page comes from