blob: fd957b398a2a4e1eedafc626a7a03bcec0e53e56 [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.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <stddef.h>
18
19typedef enum { MBS_ALIGN_LEFT, MBS_ALIGN_RIGHT, MBS_ALIGN_CENTER } mbs_align_t;
20
21enum {
22 /* Use unibyte mode for invalid multibyte strings or
23 or when heap memory is exhausted. */
24 MBA_UNIBYTE_FALLBACK = 0x0001,
25
26#if 0 /* Other possible options. */
27 /* Skip invalid multibyte chars rather than failing */
28 MBA_IGNORE_INVALID = 0x0002,
29
30 /* Align multibyte strings using "figure space" (\u2007) */
31 MBA_USE_FIGURE_SPACE = 0x0004,
32
33 /* Don't add any padding */
34 MBA_TRUNCATE_ONLY = 0x0008,
35
36 /* Don't truncate */
37 MBA_PAD_ONLY = 0x0010,
38#endif
39};
40
41extern size_t mbs_truncate(char *str, size_t *width);
42
43extern size_t mbsalign (const char *src, char *dest,
44 size_t dest_size, size_t *width,
45 mbs_align_t align, int flags);