Bump to 1.1
[platform/upstream/libunistring.git] / doc / unilbrk.texi
1 @node unilbrk.h
2 @chapter Line breaking @code{<unilbrk.h>}
3
4 @cindex line breaks
5 @cindex breaks, line
6 @cindex wrapping
7 This include file declares functions for determining where in a string
8 line breaks could or should be introduced, in order to make the displayed
9 string fit into a column of given width.
10
11 These functions are locale dependent.  The @var{encoding} argument identifies
12 the encoding (e.g@. @code{"ISO-8859-2"} for Polish).
13
14 The following enumerated values indicate whether, at a given position, a line
15 break is possible or not.  Given an string @var{s} as an array
16 @code{@var{s}[0..@var{n}-1]} and a position @var{i}, the values have the
17 following meanings:
18
19 @deftypevr Constant int UC_BREAK_MANDATORY
20 This value indicates that @code{@var{s}[@var{i}]} is a line break character.
21 @end deftypevr
22
23 @deftypevr Constant int UC_BREAK_CR_BEFORE_LF
24 This value is a variant of @code{UC_BREAK_MANDATORY}.  It indicates that
25 @code{@var{s}[@var{i}]} is a CR character and that @code{@var{s}[@var{i+1}]}
26 is a LF character.
27 @end deftypevr
28
29 @deftypevr Constant int UC_BREAK_POSSIBLE
30 This value indicates that a line break may be inserted between
31 @code{@var{s}[@var{i}-1]} and @code{@var{s}[@var{i}]}.
32 @end deftypevr
33
34 @deftypevr Constant int UC_BREAK_HYPHENATION
35 This value indicates that a hyphen and a line break may be inserted between
36 @code{@var{s}[@var{i}-1]} and @code{@var{s}[@var{i}]}.  But beware of language
37 dependent hyphenation rules.
38 @end deftypevr
39
40 @deftypevr Constant int UC_BREAK_PROHIBITED
41 This value indicates that @code{@var{s}[@var{i}-1]} and @code{@var{s}[@var{i}]}
42 must not be separated.
43 @end deftypevr
44
45 @deftypevr Constant int UC_BREAK_UNDEFINED
46 This value is not used as a return value; rather, in the overriding argument of
47 the @code{u*_width_linebreaks} functions, it indicates the absence of an
48 override.
49 @end deftypevr
50
51 The following functions determine the positions at which line breaks are
52 possible.
53
54 @deftypefun void u8_possible_linebreaks (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
55 @deftypefunx void u16_possible_linebreaks (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
56 @deftypefunx void u32_possible_linebreaks (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
57 @deftypefunx void ulc_possible_linebreaks (const@tie{}char@tie{}*@var{s}, size_t@tie{}@var{n}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
58 Determines the line break points in @var{s}, and stores the result at
59 @code{@var{p}[0..@var{n}-1]}.  Every @code{@var{p}[@var{i}]} is assigned one of
60 the values @code{UC_BREAK_MANDATORY}, @code{UC_BREAK_CR_BEFORE_LF},
61 @code{UC_BREAK_POSSIBLE}, @code{UC_BREAK_HYPHENATION},
62 @code{UC_BREAK_PROHIBITED}.
63 @end deftypefun
64
65 The following functions determine where line breaks should be inserted so that
66 each line fits in a given width, when output to a device that uses
67 non-proportional fonts.
68
69 @deftypefun int u8_width_linebreaks (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n}, int@tie{}@var{width}, int@tie{}@var{start_column}, int@tie{}@var{at_end_columns}, const@tie{}char@tie{}*@var{override}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
70 @deftypefunx int u16_width_linebreaks (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n}, int@tie{}@var{width}, int@tie{}@var{start_column}, int@tie{}@var{at_end_columns}, const@tie{}char@tie{}*@var{override}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
71 @deftypefunx int u32_width_linebreaks (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n}, int@tie{}@var{width}, int@tie{}@var{start_column}, int@tie{}@var{at_end_columns}, const@tie{}char@tie{}*@var{override}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
72 @deftypefunx int ulc_width_linebreaks (const@tie{}char@tie{}*@var{s}, size_t@tie{}@var{n}, int@tie{}@var{width}, int@tie{}@var{start_column}, int@tie{}@var{at_end_columns}, const@tie{}char@tie{}*@var{override}, const@tie{}char@tie{}*@var{encoding}, char@tie{}*@var{p})
73 Chooses the best line breaks, assuming that every character occupies a width
74 given by the @code{uc_width} function (see @ref{uniwidth.h}).
75
76 The string is @code{@var{s}[0..@var{n}-1]}.
77
78 The maximum number of columns per line is given as @var{width}.
79 The starting column of the string is given as @var{start_column}.
80 If the algorithm shall keep room after the last piece, this amount of room can
81 be given as @var{at_end_columns}.
82
83 @var{override} is an optional override; if
84 @code{@var{override}[@var{i}] != UC_BREAK_UNDEFINED},
85 @code{@var{override}[@var{i}]} takes precedence over @code{@var{p}[@var{i}]}
86 as returned by the @code{u*_possible_linebreaks} function.
87
88 The given @var{encoding} is used for disambiguating widths in @code{uc_width}.
89
90 Returns the column after the end of the string, and stores the result at
91 @code{@var{p}[0..@var{n}-1]}.  Every @code{@var{p}[@var{i}]} is assigned one of
92 the values @code{UC_BREAK_MANDATORY}, @code{UC_BREAK_CR_BEFORE_LF},
93 @code{UC_BREAK_POSSIBLE}, @code{UC_BREAK_HYPHENATION},
94 @code{UC_BREAK_PROHIBITED}.  Here the value @code{UC_BREAK_POSSIBLE} indicates
95 that a line break @emph{should} be inserted.
96 @end deftypefun