]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/utf8.h
Turn VALGRIND variable into a meson configuration switch
[thirdparty/systemd.git] / src / basic / utf8.h
CommitLineData
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 21bool unichar_is_valid(char32_t c);
f3ee6297 22
7991ac34 23const char *utf8_is_valid(const char *s) _pure_;
7f110ff9
LP
24char *ascii_is_valid(const char *s) _pure_;
25
0ade5ffe 26bool 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
29char *utf8_escape_invalid(const char *s);
30char *utf8_escape_non_printable(const char *str);
ba961854 31
c932fb71 32size_t utf8_encode_unichar(char *out_utf8, char32_t g);
2e3d0692 33char *utf16_to_utf8(const void *s, size_t length);
02a36bc9
DR
34
35int utf8_encoded_valid_unichar(const char *str);
c932fb71 36int utf8_encoded_to_unichar(const char *str, char32_t *ret_unichar);
04166cb7 37
c932fb71 38static inline bool utf16_is_surrogate(char16_t c) {
04166cb7
TG
39 return (0xd800 <= c && c <= 0xdfff);
40}
41
c932fb71 42static inline bool utf16_is_trailing_surrogate(char16_t c) {
04166cb7
TG
43 return (0xdc00 <= c && c <= 0xdfff);
44}
45
c932fb71 46static 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
50size_t utf8_n_codepoints(const char *str);
3f536d5b 51size_t utf8_console_width(const char *str);