bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 1 | /* Align/Truncate a string in a given screen width |
| 2 | Copyright (C) 2009-2010 Free Software Foundation, Inc. |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 3 | Copyright (C) 2010-2013 Karel Zak <kzak@redhat.com> |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 4 | |
| 5 | This program is free software: you can redistribute it and/or modify |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 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 |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 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/>. */ |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 17 | #ifndef UTIL_LINUX_MBSALIGN_H |
| 18 | # define UTIL_LINUX_MBSALIGN_H |
| 19 | # include <stddef.h> |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 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); |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 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 char *mbs_safe_encode(const char *s, size_t *width); |
| 53 | extern char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf); |
| 54 | extern size_t mbs_safe_encode_size(size_t bytes); |
| 55 | |
| 56 | #endif /* UTIL_LINUX_MBSALIGN_H */ |