1 /*
2     $Id: unicode.h 2550 2021-03-20 01:04:25Z soci $
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 along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 #ifndef UNICODE_H
20 #define UNICODE_H
21 #include <stdio.h>
22 #include "attributes.h"
23 #include "inttypes.h"
24 #include "stdbool.h"
25 
26 struct ubuff_s {
27     uchar_t *data;
28     uint32_t len, p;
29 };
30 
31 struct str_t;
32 
33 extern FAST_CALL unsigned int utf8in(const uint8_t *, uchar_t *);
34 extern FAST_CALL unsigned int utf8out(uchar_t, uint8_t *);
35 extern MUST_CHECK bool extend_ubuff(struct ubuff_s *);
36 extern MUST_CHECK bool unfc(struct ubuff_s *);
37 extern MUST_CHECK bool unfkc(struct str_t *, const struct str_t *, int);
38 extern size_t argv_print(const char *, FILE *);
39 extern size_t makefile_print(const char *, FILE *);
40 extern void printable_print(const uint8_t *, FILE *);
41 extern size_t printable_print2(const uint8_t *, FILE *, size_t);
42 extern void caret_print(const uint8_t *, FILE *, size_t);
43 extern size_t calcpos(const uint8_t *, size_t);
44 
utf8len(uchar_t ch)45 static inline unsigned int utf8len(uchar_t ch) {
46     if (ch < 0x80) return 1;
47     if (ch < 0xe0) return 2;
48     if (ch < 0xf0) return 3;
49     if (ch < 0xf8) return 4;
50     if (ch < 0xfc) return 5;
51     return 6;
52 }
53 #endif
54