]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/mbsalign.h
Merge branch 'typos' of https://github.com/kerolasa/util-linux
[thirdparty/util-linux.git] / include / mbsalign.h
1 /* Align/Truncate a string in a given screen width
2 Copyright (C) 2009-2010 Free Software Foundation, Inc.
3 Copyright (C) 2010-2013 Karel Zak <kzak@redhat.com>
4
5 This program is free software: you can redistribute it and/or modify
6 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
8 (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/>. */
17 #ifndef UTIL_LINUX_MBSALIGN_H
18 # define UTIL_LINUX_MBSALIGN_H
19 # include <stddef.h>
20
21 typedef enum { MBS_ALIGN_LEFT, MBS_ALIGN_RIGHT, MBS_ALIGN_CENTER } mbs_align_t;
22
23 enum {
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
43 extern size_t mbs_truncate(char *str, size_t *width);
44
45 extern size_t mbsalign (const char *src, char *dest,
46 size_t dest_size, size_t *width,
47 mbs_align_t align, int flags);
48
49 extern size_t mbsalign_with_padding (const char *src, char *dest, size_t dest_size,
50 size_t *width, mbs_align_t align, int flags,
51 int padchar);
52
53 extern size_t mbs_safe_nwidth(const char *buf, size_t bufsz, size_t *sz);
54 extern size_t mbs_safe_width(const char *s);
55
56 extern char *mbs_safe_encode(const char *s, size_t *width);
57 extern char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf, const char *safechars);
58 extern size_t mbs_safe_encode_size(size_t bytes);
59
60 extern char *mbs_invalid_encode(const char *s, size_t *width);
61 extern char *mbs_invalid_encode_to_buffer(const char *s, size_t *width, char *buf);
62
63 #endif /* UTIL_LINUX_MBSALIGN_H */