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