GRAPHEME_NEXT_LINE_BREAK_UTF8(3)
π 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
- nixos 26.05: libgrapheme 3.0.0
- nixpkgs unstable: libgrapheme 3.0.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms