1 /***
2 This file is part of eudev, forked from systemd
3
4 Copyright 2012 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #pragma once
21
22 #include <stdbool.h>
23
24 #include "macro.h"
25
26 bool unichar_is_valid(uint32_t c);
27
28 char *ascii_is_valid(const char *s) _pure_;
29
30 bool utf8_is_printable_newline(const char* str, size_t length, bool newline) _pure_;
utf8_is_printable(const char * str,size_t length)31 _pure_ static inline bool utf8_is_printable(const char* str, size_t length) {
32 return utf8_is_printable_newline(str, length, true);
33 }
34
35 size_t utf8_encode_unichar(char *out_utf8, uint32_t g);
36 char *utf16_to_utf8(const void *s, size_t length);
37
38 int utf8_encoded_valid_unichar(const char *str);
39 int utf8_encoded_to_unichar(const char *str);
40
utf16_is_surrogate(uint16_t c)41 static inline bool utf16_is_surrogate(uint16_t c) {
42 return (0xd800 <= c && c <= 0xdfff);
43 }
44
utf16_is_trailing_surrogate(uint16_t c)45 static inline bool utf16_is_trailing_surrogate(uint16_t c) {
46 return (0xdc00 <= c && c <= 0xdfff);
47 }
48
utf16_surrogate_pair_to_unichar(uint16_t lead,uint16_t trail)49 static inline uint32_t utf16_surrogate_pair_to_unichar(uint16_t lead, uint16_t trail) {
50 return ((lead - 0xd800) << 10) + (trail - 0xdc00) + 0x10000;
51 }
52