1 /* Line breaking of Unicode strings. 2 Copyright (C) 2001-2003, 2005-2021 Free Software Foundation, Inc. 3 Written by Bruno Haible <bruno@clisp.org>, 2001. 4 5 This file is free software. 6 It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+". 7 You can redistribute it and/or modify it under either 8 - the terms of the GNU Lesser General Public License as published 9 by the Free Software Foundation; either version 3, or (at your 10 option) any later version, or 11 - the terms of the GNU General Public License as published by the 12 Free Software Foundation; either version 2, or (at your option) 13 any later version, or 14 - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+". 15 16 This file is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 Lesser General Public License and the GNU General Public License 20 for more details. 21 22 You should have received a copy of the GNU Lesser General Public 23 License and of the GNU General Public License along with this 24 program. If not, see <https://www.gnu.org/licenses/>. */ 25 26 #ifndef _UNILBRK_H 27 #define _UNILBRK_H 28 29 /* Get size_t. */ 30 #include <stddef.h> 31 32 #include "unitypes.h" 33 34 /* Get locale_charset() declaration. */ 35 #include "localcharset.h" 36 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 43 /* These functions are locale dependent. The encoding argument identifies 44 the encoding (e.g. "ISO-8859-2" for Polish). */ 45 46 47 /* Line breaking. */ 48 49 enum 50 { 51 UC_BREAK_UNDEFINED, 52 UC_BREAK_PROHIBITED, 53 UC_BREAK_POSSIBLE, 54 UC_BREAK_MANDATORY, 55 UC_BREAK_HYPHENATION 56 }; 57 58 /* Determine the line break points in S, and store the result at p[0..n-1]. 59 p[i] = UC_BREAK_MANDATORY means that s[i] is a line break character. 60 p[i] = UC_BREAK_POSSIBLE means that a line break may be inserted between 61 s[i-1] and s[i]. 62 p[i] = UC_BREAK_HYPHENATION means that a hyphen and a line break may be 63 inserted between s[i-1] and s[i]. But beware of language dependent 64 hyphenation rules. 65 p[i] = UC_BREAK_PROHIBITED means that s[i-1] and s[i] must not be separated. 66 */ 67 extern void 68 u8_possible_linebreaks (const uint8_t *s, size_t n, 69 const char *encoding, char *_UC_RESTRICT p); 70 extern void 71 u16_possible_linebreaks (const uint16_t *s, size_t n, 72 const char *encoding, char *_UC_RESTRICT p); 73 extern void 74 u32_possible_linebreaks (const uint32_t *s, size_t n, 75 const char *encoding, char *_UC_RESTRICT p); 76 extern void 77 ulc_possible_linebreaks (const char *s, size_t n, 78 const char *encoding, char *_UC_RESTRICT p); 79 80 /* Choose the best line breaks, assuming the uc_width function. 81 The string is s[0..n-1]. The maximum number of columns per line is given 82 as WIDTH. The starting column of the string is given as START_COLUMN. 83 If the algorithm shall keep room after the last piece, they can be given 84 as AT_END_COLUMNS. 85 o is an optional override; if o[i] != UC_BREAK_UNDEFINED, o[i] takes 86 precedence over p[i] as returned by the *_possible_linebreaks function. 87 The given ENCODING is used for disambiguating widths in uc_width. 88 Return the column after the end of the string, and store the result at 89 p[0..n-1]. 90 */ 91 extern int 92 u8_width_linebreaks (const uint8_t *s, size_t n, int width, 93 int start_column, int at_end_columns, 94 const char *o, const char *encoding, 95 char *_UC_RESTRICT p); 96 extern int 97 u16_width_linebreaks (const uint16_t *s, size_t n, int width, 98 int start_column, int at_end_columns, 99 const char *o, const char *encoding, 100 char *_UC_RESTRICT p); 101 extern int 102 u32_width_linebreaks (const uint32_t *s, size_t n, int width, 103 int start_column, int at_end_columns, 104 const char *o, const char *encoding, 105 char *_UC_RESTRICT p); 106 extern int 107 ulc_width_linebreaks (const char *s, size_t n, int width, 108 int start_column, int at_end_columns, 109 const char *o, const char *encoding, 110 char *_UC_RESTRICT p); 111 112 113 #ifdef __cplusplus 114 } 115 #endif 116 117 118 #endif /* _UNILBRK_H */