fmt_utf8(3)
β¨ fmt_utf8 β encode 31-bit unsigned integer using UTF-8 rules β¨
okay bestie so this one's from the Library Functions Manual (section 3, library calls, you know the vibe) and it's genuinely so cute, let me put you on π
πΈ NAME πΈ
fmt_utf8 β encode 31-bit unsigned integer using UTF-8 rules
π SYNTAX π
#include <libowfat/fmt.h>
size_t fmt_utf8(char *dest,uint32_t source);
π DESCRIPTION π
so fmt_utf8 takes a 31-bit unsigned integer and encodes it using the UTF-8 rules. that's the whole job. iconic behaviour, no notes π«Ά
the output can be anywhere from 1 byte (for values 0-0x7f) all the way up to 5 bytes (for values 0x4000000-0x7fffffff). yes bestie, FIVE. it's giving stretchy π
heads up: values larger than 0x7fffffff cannot be represented in this encoding. like, at all. there is no space for them, that's the ceiling, periodt.
now the fun part: if dest equals FMT_LEN (i.e. it's NULL), fmt_utf8 doesn't write anything β it just returns the number of bytes it would have written. so it's a little preview, a little "here's how much room you'd need, bestie" β¨
and for convenience, fmt.h defines the integer FMT_UTF8 to be big enough to contain every possible fmt_utf8 output. so like, that's your buffer size girlie, use it π
π NOTE π
okay so this is the part where it gets a lil niche and I need you to pay attention π§
fmt_utf8 and scan_utf8 implement the encoding from UTF-8, but they're meant to be able to store integers, not just Unicode code points. it's a whole different use case, iykyk.
which means: values larger than 0x10ffff are not valid UTF-8 (see RFC 3629) β but they can be represented in this encoding. so fmt_utf8 will allow them. it's not gatekeeping, it's just built different π
π¦ SEE ALSO π¦
scan_utf8(3)β the other half of this duo, go read it fr fr
and that's the page bestie!! π this one lives in the Library Functions Manual, fmt_utf8(3), section 3, and it didn't come with a date stamped on it β so just vibe with it as-is. slay, go encode some integers, you got this πΈβ¨π
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms