---
name: "unicode_wb_init"
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_wb_init"
---

# unicode\_wb\_init(3)

calculate word breaks

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

These functions implement the unicode word breaking algorithm. Invoke **unicode\_wb\_init**() to initialize the word 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 second parameter is the opaque pointer that was given to **unicode\_wb\_init**(); and the opaque pointer is not subject to any further interpretation by these functions.

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

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

Between the call to **unicode\_wb\_init**() and **unicode\_wb\_end**(), the callback function gets invoked exactly once for each unicode character given to **unicode\_wb\_next**() or **unicode\_wb\_next\_cnt**(). Usually each call to **unicode\_wb\_next**() results in the callback function getting invoked immediately, but it does not have to be. It's possible that a call to **unicode\_wb\_next**() returns without invoking the callback function, and some subsequent call to **unicode\_wb\_next**() (or **unicode\_wb\_end**()) invokes the callback function more than once, to catch things up. The contract is that before **unicode\_wb\_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\_wb\_next**() and **unicode\_wb\_next\_cnt**(), unless an error occurs.

Each call to the callback function reports the calculated wordbreaking status of the corresponding character in the unicode character sequence. If the parameter to the callback function is non zero, a word break is permitted *before* the corresponding character. A zero value indicates that a word break is prohibited *before* the corresponding character.

The callback function should return 0. A non-zero value indicates to the word breaking algorithm that an error has occurred. **unicode\_wb\_next**() and **unicode\_wb\_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\_wb\_next**() and **unicode\_wb\_next\_cnt**() immediately returning the same value.

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

### 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**() obtains a handle, then **unicode\_wbscan\_next**() gets repeatedly invoked 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.

A non-0 return value from **unicode\_wbscan\_next**() indicates that the word boundary is already known, and any further calls to **unicode\_wbscan\_next**() will be ignored. **unicode\_wbscan\_end**() must still be called, to obtain the unicode character count.

## SEE ALSO

**TR-29**\[1\], [**courier-unicode**(7)](/courier-unicode/7.md), [**unicode::wordbreak**(3)](/unicode::wordbreak/3.md), [**unicode\_convert\_tocase**(3)](/unicode_convert_tocase/3.md), [**unicode\_line\_break**(3)](/unicode_line_break/3.md), [**unicode\_grapheme\_break**(3)](/unicode_grapheme_break/3.md).

## AUTHOR

**Sam Varshavchik**

Author

## NOTES

- 1\.

  TR-29

  https://www.unicode.org/reports/tr29/tr29-43.html
