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