GRAPHEME_NEXT_LINE_BREAK_UTF8(3)

πŸ“¦ version 3.0.0, in nixos 26.05, nixpkgs unstable

πŸ’– NAME πŸ’–

grapheme_next_line_break_utf8 β€” bestie, this one tells you the byte-offset to the next possible line break πŸ‘‘

✨ SYNOPSIS ✨

#include <grapheme.h>

size_t
grapheme_next_line_break_utf8(const char *str, size_t len);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so picture this: grapheme_next_line_break_utf8() computes the offset in bytes to the next possible line break (peep libgrapheme(7) for the whole lore, iykyk) inside str, which is a UTF-8-encoded string of length len. Slay πŸ’…

And here's the cute part β€” if you set len to SIZE_MAX (stdint.h is already included by grapheme.h, so no extra drama needed), then str gets interpreted as NUL-terminated, and processing just stops when it bumps into a NUL-byte. Periodt 🌸

Now real talk: if your input data is not UTF-8, don't force it β€” just use grapheme_next_line_break(3) instead, she's literally built for that πŸ™ˆ

πŸŽ€ RETURN VALUES πŸŽ€

grapheme_next_line_break_utf8() hands you back the offset (in bytes) to the next possible line break in str, or 0 if str is NULL. Iconic, no notes πŸ’€

πŸ”₯ EXAMPLES πŸ”₯

/* cc (-static) -o example example.c -lgrapheme */
#include <grapheme.h>
#include <stdint.h>
#include <stdio.h>

int
main(void)
{
        /* UTF-8 encoded input */
        char *s = "T\xC3\xABst \xF0\x9F\x91\xA8\xE2\x80\x8D\xF0"
                  "\x9F\x91\xA9\xE2\x80\x8D\xF0\x9F\x91\xA6 \xF0"
                  "\x9F\x87\xBA\xF0\x9F\x87\xB8 \xE0\xA4\xA8\xE0"
                  "\xA5\x80 \xE0\xAE\xA8\xE0\xAE\xBF!";
        size_t ret, len, off;

        printf("Input: \"%s\"\n", s);

        /* print each possible line with byte-length */
        printf("possible lines in NUL-delimited input:\n");
        for (off = 0; s[off] != '\0'; off += ret) {
                ret = grapheme_next_line_break_utf8(s + off, SIZE_MAX);
                printf("%2zu bytes | %.*s\n", ret, (int)ret, s + off);
        }
        printf("\n");

        /* do the same, but this time string is length-delimited */
        len = 17;
        printf("possible lines in input delimited to %zu bytes:\n", len);
        for (off = 0; off < len; off += ret) {
                ret = grapheme_next_line_break_utf8(s + off, len - off);
                printf("%2zu bytes | %.*s\n", ret, (int)ret, s + off);
        }

        return 0;
}

🌈 SEE ALSO 🌈

grapheme_next_line_break(3), libgrapheme(7) β€” go read 'em, they're giving main character energy 🫢

🌟 STANDARDS 🌟

grapheme_next_line_break_utf8() is compliant with the Unicode 17.0.0 specification. No cap, certified ate πŸ’œ

πŸ‘‘ AUTHORS πŸ‘‘

Laslo Hunhold <dev@frign.de> β€” literal legend πŸŽ€


k byeee, this page is brought to you by suckless.org, dated 2022-10-06, and it's the GRAPHEME_NEXT_LINE_BREAK_UTF8(3) manual page β€” mwah πŸ’‹

πŸ“¦ where this page comes from