Avoid name mangling in C++ mode.
[gnulib.git] / lib / linebreak.h
1 /* linebreak.h - line breaking of Unicode strings
2    Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc.
3    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #ifndef _LINEBREAK_H
20 #define _LINEBREAK_H
21
22 /* Get size_t.  */
23 #include <stddef.h>
24
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30
31 /* Display width.  */
32
33 /* These functions are locale dependent.  The encoding argument identifies
34    the encoding (e.g. "ISO-8859-2" for Polish).  */
35
36 /* Return the encoding of the current locale.  */
37 extern const char * locale_charset (void);
38
39 /* Determine number of column positions required for UC. */
40 extern int uc_width (unsigned int uc, const char *encoding);
41
42 /* Determine number of column positions required for first N units
43    (or fewer if S ends before this) in S.  */
44 extern int u8_width (const unsigned char *s, size_t n, const char *encoding);
45 extern int u16_width (const unsigned short *s, size_t n, const char *encoding);
46 extern int u32_width (const unsigned int *s, size_t n, const char *encoding);
47
48
49 /* Line breaking.  */
50
51 enum {
52   UC_BREAK_UNDEFINED,
53   UC_BREAK_PROHIBITED,
54   UC_BREAK_POSSIBLE,
55   UC_BREAK_MANDATORY,
56   UC_BREAK_HYPHENATION
57 };
58
59 /* Determine the line break points in S, and store the result at p[0..n-1].
60    p[i] = UC_BREAK_MANDATORY means that s[i] is a line break character.
61    p[i] = UC_BREAK_POSSIBLE means that a line break may be inserted between
62           s[i-1] and s[i].
63    p[i] = UC_BREAK_HYPHENATION means that a hyphen and a line break may be
64           inserted between s[i-1] and s[i].  But beware of language dependent
65           hyphenation rules.
66    p[i] = UC_BREAK_PROHIBITED means that s[i-1] and s[i] must not be separated.
67  */
68 extern void u8_possible_linebreaks (const unsigned char *s, size_t n,
69                                     const char *encoding,
70                                     char *p);
71 extern void u16_possible_linebreaks (const unsigned short *s, size_t n,
72                                      const char *encoding,
73                                      char *p);
74 extern void u32_possible_linebreaks (const unsigned int *s, size_t n,
75                                      const char *encoding,
76                                      char *p);
77 extern void mbs_possible_linebreaks (const char *s, size_t n,
78                                      const char *encoding,
79                                      char *p);
80
81 /* Choose the best line breaks, assuming the uc_width function.
82    Return the column after the end of the string.
83    o is an optional override; if o[i] != UC_BREAK_UNDEFINED, o[i] takes
84    precedence over p[i] as returned by the *_possible_linebreaks function.
85  */
86 extern int
87        u8_width_linebreaks (const unsigned char *s, size_t n,
88                             int width, int start_column, int at_end_columns,
89                             const char *o, const char *encoding,
90                             char *p);
91 extern int
92        u16_width_linebreaks (const unsigned short *s, size_t n,
93                              int width, int start_column, int at_end_columns,
94                              const char *o, const char *encoding,
95                              char *p);
96 extern int
97        u32_width_linebreaks (const unsigned int *s, size_t n,
98                              int width, int start_column, int at_end_columns,
99                              const char *o, const char *encoding,
100                              char *p);
101 extern int
102        mbs_width_linebreaks (const char *s, size_t n,
103                              int width, int start_column, int at_end_columns,
104                              const char *o, const char *encoding,
105                              char *p);
106
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112
113 #endif /* _LINEBREAK_H */