]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
7f110ff9 LP |
3 | |
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2012 Lennart Poettering | |
7f110ff9 LP |
8 | ***/ |
9 | ||
31f7bf19 | 10 | #include <stdbool.h> |
11c3a366 TA |
11 | #include <stddef.h> |
12 | #include <stdint.h> | |
c932fb71 | 13 | #include <uchar.h> |
31f7bf19 | 14 | |
7f110ff9 | 15 | #include "macro.h" |
c932fb71 | 16 | #include "missing.h" |
7f110ff9 | 17 | |
550a40ec | 18 | #define UTF8_REPLACEMENT_CHARACTER "\xef\xbf\xbd" |
9dd7ea9a | 19 | #define UTF8_BYTE_ORDER_MARK "\xef\xbb\xbf" |
550a40ec | 20 | |
c932fb71 | 21 | bool unichar_is_valid(char32_t c); |
f3ee6297 | 22 | |
7991ac34 | 23 | const char *utf8_is_valid(const char *s) _pure_; |
7f110ff9 LP |
24 | char *ascii_is_valid(const char *s) _pure_; |
25 | ||
0ade5ffe | 26 | bool utf8_is_printable_newline(const char* str, size_t length, bool newline) _pure_; |
6ed62be0 LP |
27 | #define utf8_is_printable(str, length) utf8_is_printable_newline(str, length, true) |
28 | ||
29 | char *utf8_escape_invalid(const char *s); | |
30 | char *utf8_escape_non_printable(const char *str); | |
ba961854 | 31 | |
c932fb71 | 32 | size_t utf8_encode_unichar(char *out_utf8, char32_t g); |
2e3d0692 | 33 | char *utf16_to_utf8(const void *s, size_t length); |
02a36bc9 DR |
34 | |
35 | int utf8_encoded_valid_unichar(const char *str); | |
c932fb71 | 36 | int utf8_encoded_to_unichar(const char *str, char32_t *ret_unichar); |
04166cb7 | 37 | |
c932fb71 | 38 | static inline bool utf16_is_surrogate(char16_t c) { |
04166cb7 TG |
39 | return (0xd800 <= c && c <= 0xdfff); |
40 | } | |
41 | ||
c932fb71 | 42 | static inline bool utf16_is_trailing_surrogate(char16_t c) { |
04166cb7 TG |
43 | return (0xdc00 <= c && c <= 0xdfff); |
44 | } | |
45 | ||
c932fb71 | 46 | static inline char32_t utf16_surrogate_pair_to_unichar(char16_t lead, char16_t trail) { |
04166cb7 TG |
47 | return ((lead - 0xd800) << 10) + (trail - 0xdc00) + 0x10000; |
48 | } | |
65ee8660 LP |
49 | |
50 | size_t utf8_n_codepoints(const char *str); | |
3f536d5b | 51 | size_t utf8_console_width(const char *str); |