]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/mbsalign.h
include: add DragonFlyBSD GPT partition types
[thirdparty/util-linux.git] / include / mbsalign.h
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-or-later
3 *
4 * Align/Truncate a string in a given screen width
5 * Copyright (C) 2009-2010 Free Software Foundation, Inc.
6 * Copyright (C) 2010-2013 Karel Zak <kzak@redhat.com>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation, either version 2.1 of the License, or (at your
11 * option) any later version.
12 */
13 #ifndef UTIL_LINUX_MBSALIGN_H
14 # define UTIL_LINUX_MBSALIGN_H
15 # include <stddef.h>
16
17 typedef enum { MBS_ALIGN_LEFT, MBS_ALIGN_RIGHT, MBS_ALIGN_CENTER } mbs_align_t;
18
19 enum {
20 /* Use unibyte mode for invalid multibyte strings or
21 or when heap memory is exhausted. */
22 MBA_UNIBYTE_FALLBACK = 0x0001,
23
24 #if 0 /* Other possible options. */
25 /* Skip invalid multibyte chars rather than failing */
26 MBA_IGNORE_INVALID = 0x0002,
27
28 /* Align multibyte strings using "figure space" (\u2007) */
29 MBA_USE_FIGURE_SPACE = 0x0004,
30
31 /* Don't add any padding */
32 MBA_TRUNCATE_ONLY = 0x0008,
33
34 /* Don't truncate */
35 MBA_PAD_ONLY = 0x0010,
36 #endif
37 };
38
39 extern size_t mbs_truncate(char *str, size_t *width);
40
41 extern size_t mbsalign (const char *src, char *dest,
42 size_t dest_size, size_t *width,
43 mbs_align_t align, int flags);
44
45 extern size_t mbsalign_with_padding (const char *src, char *dest, size_t dest_size,
46 size_t *width, mbs_align_t align, int flags,
47 int padchar);
48
49 extern size_t mbs_safe_nwidth(const char *buf, size_t bufsz, size_t *sz);
50 extern size_t mbs_safe_width(const char *s);
51
52 extern size_t mbs_nwidth(const char *buf, size_t bufsz);
53 extern size_t mbs_width(const char *s);
54
55 extern char *mbs_safe_encode(const char *s, size_t *width);
56 extern char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf, const char *safechars);
57 extern size_t mbs_safe_encode_size(size_t bytes);
58
59 extern char *mbs_invalid_encode(const char *s, size_t *width);
60 extern char *mbs_invalid_encode_to_buffer(const char *s, size_t *width, char *buf);
61
62 #endif /* UTIL_LINUX_MBSALIGN_H */