UNICODE::LINEBREAK(3)

πŸ’– UNICODE::LINEBREAK(3) πŸ’–

okay bestie, pull up a chair, we're doing unicode::linebreak from the Courier Unicode Library today and honestly?? it's giving "buffer girlboss" energy. it's all about unicode line-breaking rules πŸ’… and it is lowkey iconic.


✨ NAME ✨

unicode::linebreak_callback_base, unicode::linebreak_callback_save_buf, unicode::linebreakc_callback_base, unicode::linebreak_iter, unicode::linebreakc_iter β€” unicode line-breaking rules πŸŽ€


🌸 SYNOPSIS 🌸

#include <courier-unicode.h>

class linebreak : public unicode::linebreak_callback_base {

public:

    using unicode::linebreak_callback_base::operator<<;
    using unicode::linebreak_callback_base::operator();
    int callback(int linebreak_code)
    {
        // ...
    }
};

char32_t c;
std::u32string buf;

linebreak compute_linebreak;

compute_linebreak.set_opts(UNICODE_LB_OPT_SYBREAK);
compute_linebreak << c;

compute_linebreak(buf);
compute_linebreak(buf.begin(), buf.end());

compute_linebreak.finish();

// ...

unicode::linebreak_callback_save_buf linebreaks;

std::list<int> lb=linebreaks.lb_buf;

class linebreakc : public unicode::linebreakc_callback_base {

public:

    using unicode::linebreak_callback_base::operator<<;
    using unicode::linebreak_callback_base::operator();
    int callback(int linebreak_code, char32_t ch)
    {
        // ...
    }
};

// ...

std::u32string buf;

typedef unicode::linebreak_iter<std::u32string::const_iterator> iter_t;

iter_t beg_iter(buf.begin(), buf.end()), end_iter;

beg_iter.set_opts(UNICODE_LB_OPT_SYBREAK);

std::vector<int> linebreaks;

std::copy(beg_iter, end_iter, std::back_insert_iterator<std::vector<int>>(linebreaks));

// ...

typedef unicode::linebreakc_iter<std::u32string::const_iterator> iter_t;

iter_t beg_iter(buf.begin(), buf.end()), end_iter;

beg_iter.set_opts(UNICODE_LB_OPT_SYBREAK);

std::vector<std::pair<int, char32_t>> linebreaks;

std::copy(beg_iter, end_iter, std::back_insert_iterator<std::vector<int>>(linebreaks));

πŸ¦‹ DESCRIPTION πŸ¦‹

so unicode::linebreak_callback_base is a C++ binding for the unicode line-breaking rule implementation described over in unicode_line_break(3). no cap 🧚

the callback vibe check πŸ’Œ

you subclass unicode::linebreak_callback_base and implement callback(), which is virtually inherited from unicode::linebreak_callback_base. that callback() function lowkey receives the output values from the line-breaking algorithm β€” the UNICODE_LB_MANDATORY, UNICODE_LB_NONE, or the UNICODE_LB_ALLOWED value β€” and it does that for each unicode character. periodt ✨

callback() should return 0. a non-zero return reports an error, and that error stops the line-breaking algorithm entirely 😭 β€” so like, don't do that unless you mean it. see unicode_line_break(3) for more info.

the other flavor πŸ“

the alternate unicode::linebreakc_callback_base interface uses a virtually inherited callback() that takes two parameters: the line-break code value, and the corresponding unicode character. two for the price of one, we love to see it πŸ’…

feeding it characters 🌈

the input unicode characters for the line-breaking algorithm come in two ways:

  • via the << operator, one unicode character at a time 🐌
  • via the () operator, where you pass either a container, or a beginning and an ending iterator value for an input sequence of unicode characters ✨

and finish() is the little "that's all folks" β€” it indicates the end of the unicode character sequence. πŸŽ€

set_opts sets the line-breaking options (peep unicode_lb_set_opts() for more info, iykyk).

saving those breaks πŸ’Ύ

unicode::linebreak_callback_save_buf is a subclass that implements callback() by saving the linebreak codes into a std::list. bestie is literally just a little hoarder of line breaks, and honestly? valid.

iterator era πŸ‘‘

the linebreak_iter template implements an input iterator over ints. the template parameter is an input iterator over unicode chars. the constructor's parameters are a beginning and an ending iterator value for a sequence of char32_t. this constructs the beginning iterator value for a sequence of ints consisting of line-break values (UNICODE_LB_MANDATORY, UNICODE_LB_NONE, or UNICODE_LB_ALLOWED) corresponding to each char32_t in the underlying sequence. and the default constructor creates the ending iterator value for that sequence. 🫢

the iterator implements a set_opts() method that sets the options for the line-breaking algorithm.

the linebreakc_iter template implements a similar input iterator, with the difference that it ends up iterating over a std::pair of line-breaking values and the corresponding char32_t from the underlying input sequence. so it's like linebreak_iter but it brought a plus-one πŸŽ€βœ¨


πŸ‘€ SEE ALSO πŸ‘€

courier-unicode(7), unicode_line_break(3).


πŸ‘‘ AUTHOR πŸ‘‘

Sam Varshavchik Author


mwah πŸ’‹ that's the whole page bestie, you ate. this was Courier Unicode Library, dated 04/12/2026, and you were reading UNICODE::LINEBREAK(3) β€” go break some lines responsibly πŸ¦‹πŸ’–βœ¨

πŸ“¦ where this page comes from