---
name: "unicode_line_break"
section: "3"
platform: "linux"
package: "libcourier-unicode-dev"
version: "2.3.2-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/unicode_line_break"
---

# unicode\_line\_break(3)

calculate mandatory or allowed line breaks

## 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

## 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

These functions implement the unicode line breaking algorithm. Invoke **unicode\_lb\_init**() to initialize the line breaking algorithm. The first parameter is a callback function. The second parameter is an opaque pointer. The callback function gets invoked with two parameters. The first parameter is one of three values: UNICODE\_LB\_MANDATORY, UNICODE\_LB\_NONE, or UNICODE\_LB\_ALLOWED, as described below. The second parameter is the opaque pointer that was passed to **unicode\_lb\_init**(); the opaque pointer is not subject to any further interpretation by these functions.

**unicode\_lb\_init**() returns an opaque handle. Repeated invocations of **unicode\_lb\_next**(), passing the handle and one unicode character at a time, defines a sequence of unicode characters over which the line breaking algorithm calculation takes place. **unicode\_lb\_next\_cnt**() is a shortcut for invoking **unicode\_lb\_next**() repeatedly over an array cptr containing cnt unicode characters.

**unicode\_lb\_end**() denotes the end of the unicode character sequence. After the call to **unicode\_lb\_end**() the line breaking unicode\_lb\_info\_t handle is no longer valid.

Between the call to **unicode\_lb\_init**() and **unicode\_lb\_end**(), the callback function gets invoked exactly once for each unicode character given to **unicode\_lb\_next**() or **unicode\_lb\_next\_cnt**(). Usually each call to **unicode\_lb\_next**() results in the callback function getting invoked immediately, but it does not have to be. It's possible that a call to **unicode\_lb\_next**() returns without invoking the callback function, and some subsequent call to **unicode\_lb\_next**() (or **unicode\_lb\_end**()) invokes the callback function more than once, to catch up. The contract is that before **unicode\_lb\_end**() returns, the callback function gets invoked the exact number of times as the number of characters in the unicode sequence defined by the intervening calls to **unicode\_lb\_next**() and **unicode\_lb\_next\_cnt**(), unless an error occurs.

Each call to the callback function reports the calculated line breaking status of the corresponding character in the unicode character sequence:

UNICODE\_LB\_MANDATORY

A line break is MANDATORY *before* the corresponding character.

UNICODE\_LB\_NONE

A line break is PROHIBITED *before* the corresponding character.

UNICODE\_LB\_ALLOWED

A line break is OPTIONAL *before* the corresponding character.

The callback function should return 0. A non-zero value indicates to 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 each call to the callback function returned zero. A non zero return from the callback function results in **unicode\_lb\_next**() and **unicode\_lb\_next\_cnt**() immediately returning the same value.

**unicode\_lb\_end**() must be invoked to destroy the line breaking handle even if **unicode\_lb\_next**() and **unicode\_lb\_next\_cnt**() returned an error indication. It's also possible that, under normal circumstances, **unicode\_lb\_end**() invokes the callback function one or more times. The return value from **unicode\_lb\_end**() has the same meaning as from **unicode\_lb\_next**() and **unicode\_lb\_next\_cnt**(); however in all cases after **unicode\_lb\_end**() returns the line breaking handle is no longer valid.

### Alternative callback function

**unicode\_lbc\_init**(), **unicode\_lbc\_next**(), **unicode\_lbc\_next\_cnt**(), **unicode\_lbc\_end**() are alternative functions that implement the same algorithm. The only difference is that the callback function receives an extra parameter, the unicode character value to which the line breaking status applies to, passed through from the input unicode character sequence.

### Options

**unicode\_lb\_set\_opts**() and **unicode\_lbc\_set\_opts**() enable 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. *opts* is a bitmask that can contain the following values:

UNICODE\_LB\_OPT\_PRBREAK

Enables a modified LB24 rule. This prevents plus signs, as 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); 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.

## SEE ALSO

[**courier-unicode**(7)](/courier-unicode/7.md), **unicode::linebreak**(3), **TR-14**\[1\]

## AUTHOR

**Sam Varshavchik**

Author

## NOTES

- 1\.

  TR-14

  https://www.unicode.org/reports/tr14/tr14-51.html
