UNICODE_WORD_BREAK(3)

πŸ’– UNICODE_WORD_BREAK(3) β€” bestie edition πŸ’–

okay so this is UNICODE_WORD_BREAK(3) from the Courier Unicode Library, and it's literally the whole "where do words end" saga. pull up a chair 🫢


✨ NAME ✨

unicode_wb_init, unicode_wb_next, unicode_wb_next_cnt, unicode_wb_end, unicode_wbscan_init, unicode_wbscan_next, unicode_wbscan_end, unicode_word_break β€” calculate word breaks πŸ¦‹


✨ SYNOPSIS ✨

#include <courier-unicode.h>

unicode_wb_info_t unicode_wb_init(int (*cb_func)(int, void *),
                                  void *cb_arg);

int unicode_wb_next(unicode_wb_info_t wb, char32_t c);

int unicode_wb_next_cnt(unicode_wb_info_t wb, const char32_t *cptr,
                        size_t cnt);

int unicode_wb_end(unicode_wb_info_t wb);

unicode_wbscan_info_t unicode_wbscan_init(void);

int unicode_wbscan_next(unicode_wbscan_info_t wbs, char32_t c);

size_t unicode_wbscan_end(unicode_wbscan_info_t wbs);

✨ DESCRIPTION ✨

so these functions are the full unicode word breaking algorithm, no cap. πŸŽ€

call unicode_wb_init() to kick the whole word breaking thing off. first parameter is a callback function, second parameter is an opaque pointer. that callback gets invoked with two parameters: the second one is the same opaque pointer you handed to unicode_wb_init(), and ngl these functions do not interpret that pointer in any way, shape or form. it's just vibing there, untouched. πŸ™ˆ

unicode_wb_init() hands you back an opaque handle. then you call unicode_wb_next() over and over with that handle plus one unicode character at a time β€” and that whole sequence of unicode characters is the thing the word breaking algorithm does its math on. unicode_wb_next_cnt() is just the shortcut version: it repeatedly invokes unicode_wb_next() over an array cptr containing cnt unicode characters. efficient queen πŸ’…

unicode_wb_end() says "that's it, sequence over." and after you call unicode_wb_end(), the word breaking unicode_wb_info_t handle is no longer valid. gone. don't touch it. πŸ’€

between the unicode_wb_init() call and the unicode_wb_end() call, the callback function gets invoked exactly once for each unicode character you gave to unicode_wb_next() or unicode_wb_next_cnt(). usually each unicode_wb_next() call makes the callback fire right away β€” but it does not have to be that way, bestie. it's possible that a call to unicode_wb_next() returns without invoking the callback at all, and then some subsequent unicode_wb_next() call (or unicode_wb_end()) fires the callback more than once to catch up. the actual contract is: before unicode_wb_end() returns, the callback has been invoked the exact number of times equal to the number of characters in the unicode sequence defined by all those intervening unicode_wb_next() and unicode_wb_next_cnt() calls β€” unless an error happens, in which case all bets are off. 😭

every callback call reports the calculated wordbreaking status of the corresponding character in the sequence. if the parameter to the callback is non-zero, a word break is permitted before that character. a zero value means a word break is prohibited before that character. that's the whole vibe check right there ⭐

the callback should return 0. a non-zero value tells the word breaking algorithm that an error occurred. unicode_wb_next() and unicode_wb_next_cnt() return zero either if they never invoked the callback function, or if every callback call returned zero. a non-zero return from the callback makes unicode_wb_next() and unicode_wb_next_cnt() immediately return that same value, like, instantly, no hesitation. πŸ”₯

you must invoke unicode_wb_end() to destroy the word breaking handle β€” yes, even if unicode_wb_next() and unicode_wb_next_cnt() returned an error indication. also, under totally normal circumstances, unicode_wb_end() can invoke the callback function one or more times. the return value from unicode_wb_end() means the same thing as the return value from unicode_wb_next() and unicode_wb_next_cnt(). but in all cases, once unicode_wb_end() returns, the line breaking handle is no longer valid. periodt. πŸ‘‘

🌸 Word scan 🌸

unicode_wbscan_init(), unicode_wbscan_next() and unicode_wbscan_end scan for the next word boundary in a unicode character sequence. 🧚

unicode_wbscan_init() gets you a handle, then you repeatedly invoke unicode_wbscan_next() to define the unicode character sequence. unicode_wbscan_end() deallocates the handle and returns the number of leading characters in the unicode character sequence up to the first word break. iconic. ✨

a non-0 return value from unicode_wbscan_next() means the word boundary is already known, and any further calls to unicode_wbscan_next() will just be ignored. you still gotta call unicode_wbscan_end() though, because that's how you get the unicode character count. don't forget, bestie 🫢


✨ SEE ALSO ✨


✨ AUTHOR ✨

Sam Varshavchik β€” Author 🌈


✨ NOTES ✨

  1. TR-29 https://www.unicode.org/reports/tr29/tr29-47.html

and that's the whole page, bestie πŸ’œ this was Courier Unicode Library, dated 04/12/2026, page UNICODE_WORD_BREAK(3) β€” slay, bye, go break some words πŸ˜˜πŸ’…πŸŒΈ

πŸ“¦ where this page comes from