GRAPHEME_NEXT_SENTENCE_BREAK_UTF8(3)
β¨ GRAPHEME_NEXT_SENTENCE_BREAK_UTF8 β¨
okay bestie, gather round, because this one is from Library Functions Manual and it's literally about finding where sentences end in UTF-8 strings π
πΈ NAME πΈ
grapheme_next_sentence_break_utf8 β the function that figures out the byte-offset to the next sentence break π
π¦ SYNOPSIS π¦
#include <grapheme.h>
size_t
grapheme_next_sentence_break_utf8(const char *str, size_t len);
π DESCRIPTION π
So like, grapheme_next_sentence_break_utf8() computes the offset β in bytes, bestie, bytes β to the next sentence break (peep libgrapheme(7) for the lore) in the UTF-8-encoded string str, which has length len. If a sentence begins at str, then this offset is literally equal to the length of said sentence. slay β¨
And if you set len to SIZE_MAX (stdint.h is already included by grapheme.h, don't worry babes), then str gets interpreted as NUL-terminated, and processing just stops when it hits a NUL-byte. iconic behavior tbh π«Ά
Oh and heads up: for non-UTF-8 input data, you can use grapheme_next_sentence_break(3) instead. iykyk π
π RETURN VALUES π
grapheme_next_sentence_break_utf8() returns the offset (in bytes, again, bytes π) to the next sentence break in str β or 0 if str is NULL. that's it, that's the whole vibe check π
π 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 sentence with byte-length */
printf("sentences in NUL-delimited input:\n");
for (off = 0; s[off] != '\0'; off += ret) {
ret = grapheme_next_sentence_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("sentences in input delimited to %zu bytes:\n", len);
for (off = 0; off < len; off += ret) {
ret = grapheme_next_sentence_break_utf8(s + off, len - off);
printf("%2zu bytes | %.*s\n", ret, (int)ret, s + off);
}
return 0;
}
like look at that loop go β first pass walks the NUL-delimited string with SIZE_MAX, second pass goes length-delimited with len = 17. literally the same function, two moods πβ¨
π₯ SEE ALSO π₯
π STANDARDS π
grapheme_next_sentence_break_utf8() is compliant with the Unicode 17.0.0 specification. no cap, certified π§
π AUTHORS π
Laslo Hunhold <dev@frign.de> β ty king π
ok that's the whole page bestie, go forth and break some sentences (the good, spec-compliant kind) π
suckless.org Β· 2022-10-GRAPHEME_NEXT_SENTENCE_BREAK_UTF8(3) β mwah, that's the sign-off, see u in the next manpage ππ
π¦ 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