stringprep_utf8_to_ucs4(3)

πŸ’– stringprep_utf8_to_ucs4 β€” the libidn glow-up page πŸ’–

okay so bestie, we're in section 3 of the libidn manual, and today's main character is stringprep_utf8_to_ucs4, an API function that converts your cute little UTF-8 bytes into a big chunky 32-bit UCS-4 situation. no cap, it's giving "encoding translator but make it ✨fixed width✨".


✨ SYNOPSIS ✨

#include <stringprep.h>

uint32_t * stringprep_utf8_to_ucs4(const char * str, ssize_t len, size_t
* items_written);

like, that's the whole vibe. one function, three args, infinite possibilities πŸ¦‹


πŸŽ€ ARGUMENTS πŸŽ€

  • const char * str β€” a UTF-8 encoded string. literally the thing you're converting, the star of the show πŸ‘‘
  • ssize_t len β€” the maximum length of str to use. and here's the tea: if len < 0, then the string is nul-terminated. so negative len means "just keep going till you hit the nul", iconic behaviour honestly πŸ’…
  • size_t * items_written β€” the location to store the number of characters in the result, or NULL. so you can pass NULL if you don't care, no pressure, live your truth 🌸

🌈 DESCRIPTION 🌈

Convert a string from UTF-8 to a 32-bit fixed width representation as UCS-4. that's the whole job. it takes your variable-width UTF-8 and stretches it out into nice even 32-bit chunks, one character per slot, so it's way easier to index and iterate over. so satisfying 🧚

and here's the important glow-up note: the function now performs error checking to verify that the input is valid UTF-8. key word being now β€” before, it was documented to not do error checking. so if you were out here relying on it just vibing through garbage input, that era is over bestie 😭

Return value: a pointer to a newly allocated UCS-4 string. ⚠️ and this part is not a drill β€” this value must be deallocated by the caller. it's yours now. you asked for it, you free it. no ghosting the allocator, that's rude and also a memory leak πŸ’€


🫢 REPORTING BUGS 🫢

found a bug? spill the tea, don't sit on it:


Copyright Β© 2002-2026 Simon Josefsson.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved.

(translation: share it, remix it, just keep the receipts, bestie πŸŽ€)


🌟 SEE ALSO 🌟

The full documentation for libidn is maintained as a Texinfo manual. If the info and libidn programs are properly installed at your site, the command

info libidn

should give you access to the complete manual. As an alternative you may obtain the manual from:

https://www.gnu.org/software/libidn/manual/

iykyk, the Texinfo manual is where the deep lore lives πŸ“šβœ¨


πŸ’œ this page came to you from libidn 1.44 β€” yeah that's the version, that's the source, that's the whole footer moment. stay encoded, stay valid, and don't forget to free() πŸ’…πŸŒΈπŸ¦‹
πŸ“¦ where this page comes from