blob: 5eaf606e57182290d0c3106203b18e8eb56edf0e [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/* Align/Truncate a string in a given screen width
2 Copyright (C) 2009-2010 Free Software Foundation, Inc.
bigbiff7b4c7a62015-01-01 19:44:14 -05003 Copyright (C) 2010-2013 Karel Zak <kzak@redhat.com>
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05004
5 This program is free software: you can redistribute it and/or modify
bigbiff7b4c7a62015-01-01 19:44:14 -05006 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 2.1 of the License, or
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05008 (at your option) 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, see <http://www.gnu.org/licenses/>. */
bigbiff7b4c7a62015-01-01 19:44:14 -050017#ifndef UTIL_LINUX_MBSALIGN_H
18# define UTIL_LINUX_MBSALIGN_H
19# include <stddef.h>
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050020
21typedef enum { MBS_ALIGN_LEFT, MBS_ALIGN_RIGHT, MBS_ALIGN_CENTER } mbs_align_t;
22
23enum {
24 /* Use unibyte mode for invalid multibyte strings or
25 or when heap memory is exhausted. */
26 MBA_UNIBYTE_FALLBACK = 0x0001,
27
28#if 0 /* Other possible options. */
29 /* Skip invalid multibyte chars rather than failing */
30 MBA_IGNORE_INVALID = 0x0002,
31
32 /* Align multibyte strings using "figure space" (\u2007) */
33 MBA_USE_FIGURE_SPACE = 0x0004,
34
35 /* Don't add any padding */
36 MBA_TRUNCATE_ONLY = 0x0008,
37
38 /* Don't truncate */
39 MBA_PAD_ONLY = 0x0010,
40#endif
41};
42
43extern size_t mbs_truncate(char *str, size_t *width);
44
45extern size_t mbsalign (const char *src, char *dest,
46 size_t dest_size, size_t *width,
47 mbs_align_t align, int flags);
bigbiff7b4c7a62015-01-01 19:44:14 -050048
49extern size_t mbs_safe_nwidth(const char *buf, size_t bufsz, size_t *sz);
50extern size_t mbs_safe_width(const char *s);
51
52extern char *mbs_safe_encode(const char *s, size_t *width);
53extern char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf);
54extern size_t mbs_safe_encode_size(size_t bytes);
55
56#endif /* UTIL_LINUX_MBSALIGN_H */