]>
Commit | Line | Data |
---|---|---|
7f110ff9 LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
c2f1db8f | 3 | #pragma once |
7f110ff9 LP |
4 | |
5 | /*** | |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2012 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
11 | under the terms of the GNU Lesser General Public License as published by |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
7f110ff9 LP |
13 | (at your option) any later version. |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 18 | Lesser General Public License for more details. |
7f110ff9 | 19 | |
5430f7f2 | 20 | You should have received a copy of the GNU Lesser General Public License |
7f110ff9 LP |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
22 | ***/ | |
23 | ||
31f7bf19 ZJS |
24 | #include <stdbool.h> |
25 | ||
7f110ff9 LP |
26 | #include "macro.h" |
27 | ||
550a40ec ZJS |
28 | #define UTF8_REPLACEMENT_CHARACTER "\xef\xbf\xbd" |
29 | ||
f3ee6297 LP |
30 | bool unichar_is_valid(uint32_t c); |
31 | ||
7991ac34 | 32 | const char *utf8_is_valid(const char *s) _pure_; |
7f110ff9 LP |
33 | char *ascii_is_valid(const char *s) _pure_; |
34 | ||
0ade5ffe | 35 | bool utf8_is_printable_newline(const char* str, size_t length, bool newline) _pure_; |
6ed62be0 LP |
36 | #define utf8_is_printable(str, length) utf8_is_printable_newline(str, length, true) |
37 | ||
38 | char *utf8_escape_invalid(const char *s); | |
39 | char *utf8_escape_non_printable(const char *str); | |
ba961854 | 40 | |
2bb4c7e3 | 41 | size_t utf8_encode_unichar(char *out_utf8, uint32_t g); |
2e3d0692 | 42 | char *utf16_to_utf8(const void *s, size_t length); |
02a36bc9 DR |
43 | |
44 | int utf8_encoded_valid_unichar(const char *str); | |
f405e86d | 45 | int utf8_encoded_to_unichar(const char *str); |
04166cb7 TG |
46 | |
47 | static inline bool utf16_is_surrogate(uint16_t c) { | |
48 | return (0xd800 <= c && c <= 0xdfff); | |
49 | } | |
50 | ||
51 | static inline bool utf16_is_trailing_surrogate(uint16_t c) { | |
52 | return (0xdc00 <= c && c <= 0xdfff); | |
53 | } | |
54 | ||
55 | static inline uint32_t utf16_surrogate_pair_to_unichar(uint16_t lead, uint16_t trail) { | |
56 | return ((lead - 0xd800) << 10) + (trail - 0xdc00) + 0x10000; | |
57 | } |