1 /* Display width functions. 2 Copyright (C) 2001-2002, 2005, 2007, 2009-2020 Free Software Foundation, 3 Inc. 4 5 This program is free software: you can redistribute it and/or modify it 6 under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3 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 GNU 13 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 <https://www.gnu.org/licenses/>. */ 17 18 #ifndef _UNIWIDTH_H 19 #define _UNIWIDTH_H 20 21 #include "unitypes.h" 22 23 /* Get size_t. */ 24 #include <stddef.h> 25 26 /* Get locale_charset() declaration. */ 27 #include "localcharset.h" 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 34 /* Display width. */ 35 36 /* These functions are locale dependent. The encoding argument identifies 37 the encoding (e.g. "ISO-8859-2" for Polish). */ 38 39 /* Determine number of column positions required for UC. */ 40 extern int 41 uc_width (ucs4_t uc, const char *encoding) 42 _UC_ATTRIBUTE_PURE; 43 44 extern int 45 uc_width1 (ucs4_t uc) 46 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 47 __attribute__ ((__pure__)) 48 #endif 49 ; 50 51 /* Determine number of column positions required for first N units 52 (or fewer if S ends before this) in S. */ 53 extern int 54 u8_width (const uint8_t *s, size_t n, const char *encoding) 55 _UC_ATTRIBUTE_PURE; 56 extern int 57 u16_width (const uint16_t *s, size_t n, const char *encoding) 58 _UC_ATTRIBUTE_PURE; 59 extern int 60 u32_width (const uint32_t *s, size_t n, const char *encoding) 61 _UC_ATTRIBUTE_PURE; 62 63 /* Determine number of column positions required for S. */ 64 extern int 65 u8_strwidth (const uint8_t *s, const char *encoding) 66 _UC_ATTRIBUTE_PURE; 67 extern int 68 u16_strwidth (const uint16_t *s, const char *encoding) 69 _UC_ATTRIBUTE_PURE; 70 extern int 71 u32_strwidth (const uint32_t *s, const char *encoding) 72 _UC_ATTRIBUTE_PURE; 73 74 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif /* _UNIWIDTH_H */ 80