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