]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - 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>
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.
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.
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
21 typedef enum { MBS_ALIGN_LEFT
, MBS_ALIGN_RIGHT
, MBS_ALIGN_CENTER
} mbs_align_t
;
24 /* Use unibyte mode for invalid multibyte strings or
25 or when heap memory is exhausted. */
26 MBA_UNIBYTE_FALLBACK
= 0x0001,
28 #if 0 /* Other possible options. */
29 /* Skip invalid multibyte chars rather than failing */
30 MBA_IGNORE_INVALID
= 0x0002,
32 /* Align multibyte strings using "figure space" (\u2007) */
33 MBA_USE_FIGURE_SPACE
= 0x0004,
35 /* Don't add any padding */
36 MBA_TRUNCATE_ONLY
= 0x0008,
39 MBA_PAD_ONLY
= 0x0010,
43 extern size_t mbs_truncate(char *str
, size_t *width
);
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
);
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
,
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
);
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
);
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
);
63 #endif /* UTIL_LINUX_MBSALIGN_H */