UNICODE::WORDBREAK(3)
π UNICODE::WORDBREAK(3) π
okay bestie, welcome to unicode::wordbreak_callback_base and unicode::wordbreak β the C++ girlies for unicode word-breaking rules, from the Courier Unicode Library. pull up a chair, we're doing text segmentation and we're doing it cutely. π¦
β¨ SYNOPSIS β¨
#include <courier-unicode.h>
class wordbreak : public unicode::wordbreak_callback_base {
public:
using unicode::wordbreak_callback_base::operator<<;
using unicode::wordbreak_callback_base::operator();
int callback(bool flag)
{
// ...
}
};
char32_t c;
std::u32string buf;
wordbreak compute_wordbreak;
compute_wordbreak << c;
compute_wordbreak(buf);
compute_wordbreak(buf.begin(), buf.end());
compute_wordbreak.finish();
// ...
unicode_wordbreakscan scan;
scan << c;
size_t nchars=scan.finish();
πΈ DESCRIPTION πΈ
so. unicode::wordbreak_callback_base is the C++ binding for the unicode word-breaking rule implementation, which is described over in unicode_word_break(3). it's giving "glow-up of a C API". π
the move is: you subclass unicode::wordbreak_callback_base and you implement callback() β which is virtually inherited from unicode::wordbreak_callback_base, ok, so don't come for me about it. that callback() function receives the output values from the word-breaking algorithm, namely a bool indicating whether a word break exists before the unicode character in the underlying input sequence. iconic, honestly. π
callback() should return 0. a non-zero return reports an error, and that error stops the word-breaking algorithm dead. like, algorithm over, bestie. see unicode_word_break(3) for more info. no cap. π
the input unicode characters for the word-breaking algorithm get fed in two ways, pick your fighter:
- by the
<<operator, one unicode character at a time - by the
()operator, passing either a container, or a beginning and an ending iterator value for an input sequence of unicode characters
then finish() says "ok that's it, we're done with the unicode character sequence". π
now, unicode::wordbreakscan is a separate C++ binding, and it's the binding for unicode_wbscan_init(), unicode_wbscan_next() and unicode_wbscan_end() β those are all described in unicode_word_break(3). its << iterates over the unicode characters, and its finish() tells you the number of characters before the first unicode word break. and the << iterator returns a bool indicating when the first word break has already been found, so likeβ¦ further calls are not necessary. she already found it, she's done, let her rest. π
little reminder bestie: these two are different things with confusingly similar names. one gives you a callback per break, the other counts. don't mix them up or you'll be debugging at 3am. π
π SEE ALSO π
π AUTHOR π
Sam Varshavchik Author
that's the whole page, bestie, slay. π this one comes to you from the Courier Unicode Library, dated 04/12/2026, and it's the UNICODE::WORDBREAK(3) page. periodt. β¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: courier-unicode 2.6.0
- ubuntu stonking: libcourier-unicode-dev 2.6.0-2ubuntu1 Β· GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms