UNICODE_LINE_BREAK(3)

✨ NAME ✨

unicode_line_break, unicode_lb_init, unicode_lb_set_opts, unicode_lb_next, unicode_lb_next_cnt, unicode_lb_end, unicode_lbc_init, unicode_lbc_set_opts, unicode_lbc_next, unicode_lbc_next_cnt, unicode_lbc_end β€” calculate mandatory or allowed line breaks πŸ’…

(also this is the Courier Unicode Library man page, iiiin case you were wondering, bestie 🫢)


🌸 SYNOPSIS 🌸

#include <courier-unicode.h>

unicode_lb_info_t unicode_lb_init(int (*cb_func)(int, void *),
                                  void *cb_arg);

void unicode_lb_set_opts(unicode_lb_info_t lb, int opts);

int unicode_lb_next(unicode_lb_info_t lb, char32_t c);

int unicode_lb_next_cnt(unicode_lb_info_t lb, const char32_t *cptr,
                        size_t cnt);

int unicode_lb_end(unicode_lb_info_t lb);

unicode_lbc_info_t
                                    unicode_lbc_init(int (*cb_func)(int, char32_t, void *),
                                    void *cb_arg);

void unicode_lbc_set_opts(unicode_lbc_info_t lb, int opts);

int unicode_lbc_next(unicode_lb_info_t lb, char32_t c);

int unicode_lbc_next_cnt(unicode_lb_info_t lb, const char32_t *cptr,
                         size_t cnt);

int unicode_lbc_end(unicode_lb_info_t lb);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so. these functions are literally the unicode line breaking algorithm, the whole entire thing, and they eat it for breakfast πŸ”₯

Start it up with unicode_lb_init(). First parameter is a callback function. Second parameter is an opaque pointer. That callback gets called with two parameters:

  • The first one is one of three values: UNICODE_LB_MANDATORY, UNICODE_LB_NONE, or UNICODE_LB_ALLOWED, all explained below, promise πŸ’–
  • The second one is the opaque pointer you handed to unicode_lb_init(), and these functions will not touch it, interpret it, or do literally anything else with it. it's yours.

unicode_lb_init() hands back an opaque handle. Then you call unicode_lb_next() over and over, passing the handle plus, like, one unicode character at a time, and that defines the unicode character sequence that the line breaking algorithm is doing its little calculations over. And unicode_lb_next_cnt() is just the shortcut version: it does unicode_lb_next() repeatedly over an array cptr that holds cnt unicode characters. queen behavior πŸ’…

unicode_lb_end() is how you say "the unicode character sequence ends HERE." And after you call unicode_lb_end(), the unicode_lb_info_t line breaking handle is no longer valid. gone. done. don't touch it.

In between unicode_lb_init() and unicode_lb_end(), the callback function gets invoked exactly once per unicode character you gave to unicode_lb_next() or unicode_lb_next_cnt(). Usually each unicode_lb_next() call means the callback fires right away, but ngl it does not have to. It's fully possible that a unicode_lb_next() call returns without invoking the callback at all, and then some later unicode_lb_next() (or unicode_lb_end()) invokes the callback more than once to catch up. The way the contract works: before unicode_lb_end() returns, the callback gets invoked the exact number of times equal to the number of characters in the unicode sequence defined by all the unicode_lb_next() and unicode_lb_next_cnt() calls in between β€” unless an error happens, obviously πŸ™ˆ

Every callback call reports the calculated line breaking status of its corresponding character in the sequence:

  • UNICODE_LB_MANDATORY β€” a line break is MANDATORY before the corresponding character. like, you MUST break here.
  • UNICODE_LB_NONE β€” a line break is PROHIBITED before the corresponding character. absolutely not. no.
  • UNICODE_LB_ALLOWED β€” a line break is OPTIONAL before the corresponding character. your call bestie πŸ’–

The callback function should return 0. A non-zero value is you telling the line breaking algorithm that an error has occurred. unicode_lb_next() and unicode_lb_next_cnt() return zero either if they never invoked the callback function, or if every callback call returned zero. If the callback returns non-zero, unicode_lb_next() and unicode_lb_next_cnt() immediately return that same value. instant. no notes.

You must call unicode_lb_end() to destroy the line breaking handle even if unicode_lb_next() and unicode_lb_next_cnt() returned an error indication. And also, under totally normal circumstances, unicode_lb_end() might invoke the callback function one or more times. The return value from unicode_lb_end() means the same thing as it does from unicode_lb_next() and unicode_lb_next_cnt(); but in all cases, once unicode_lb_end() returns, the line breaking handle is no longer valid. periodt πŸ‘‘

πŸŽ€ Alternative callback function πŸŽ€

unicode_lbc_init(), unicode_lbc_next(), unicode_lbc_next_cnt(), unicode_lbc_end() are the alternative functions that implement the exact same algorithm. The only difference: the callback function receives an extra parameter β€” the unicode character value that the line breaking status applies to β€” passed through from the input unicode character sequence. that's it. that's the whole diff. iconic. ✨

πŸ’œ Options πŸ’œ

unicode_lb_set_opts() and unicode_lbc_set_opts() turn on non-default options for the line breaking algorithm. These functions must be called immediately after unicode_lb_init() or unicode_lbc_init(), and before any other function. Like, immediately. Right after. Don't be late.

opts is a bitmask and it can contain these values:

  • UNICODE_LB_OPT_PRBREAK β€” enables a modified LB24 rule. This stops plus signs, like in β€œC++”, from breaking. This flag adds the following rules to the LB24 rule:
                   PR x PR

                   AL x PR

                      ID x PR
  • UNICODE_LB_OPT_SYBREAK β€” tailored breaking rules for the β€œ/” character. This prevents breaking after the β€œ/” character (think URLs, bestie πŸ¦‹); including an exception to the β€œx SY” rule in LB13. This flag adds the following rules to the LB24 rule:
                   SY x EX

                   SY x AL

                   SY x ID

                      SP Γ· SY, which takes precedence over "x SY".
  • UNICODE_LB_OPT_DASHWJ β€” this flag reclassifies U+2013 and U+2014 as class WJ, prohibiting breaks before and after the m-dash and the n-dash unicode characters. no dash drama on your watch πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘

courier-unicode(7), unicode::linebreak(3), TR-14[1]


πŸ’– AUTHOR πŸ’–

Sam Varshavchik Author


⭐ NOTES ⭐

  1. TR-14 https://www.unicode.org/reports/tr14/tr14-55.html

and that's the whole page, bestie 🫢 this was Courier Unicode Library, dated 04/12/2026, and it lives in the manual as UNICODE_LINE_BREAK(3) β€” go forth and break lines correctly, ily πŸ’–βœ¨πŸŒˆ

πŸ“¦ where this page comes from