2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2012-03-12 22:22:16 +01:00
|
|
|
|
2013-04-24 04:40:26 +02:00
|
|
|
#include <stdbool.h>
|
2015-11-30 21:43:37 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2015-12-13 23:26:43 +01:00
|
|
|
#include <uchar.h>
|
2013-04-24 04:40:26 +02:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
#include "macro.h"
|
2018-12-04 08:08:15 +01:00
|
|
|
#include "missing_type.h"
|
2012-03-12 22:22:16 +01:00
|
|
|
|
2014-01-18 03:28:41 +01:00
|
|
|
#define UTF8_REPLACEMENT_CHARACTER "\xef\xbf\xbd"
|
2016-03-22 04:34:13 +01:00
|
|
|
#define UTF8_BYTE_ORDER_MARK "\xef\xbb\xbf"
|
2014-01-18 03:28:41 +01:00
|
|
|
|
2015-12-13 23:26:43 +01:00
|
|
|
bool unichar_is_valid(char32_t c);
|
2015-04-10 11:27:47 +02:00
|
|
|
|
2020-09-01 10:43:21 +02:00
|
|
|
char *utf8_is_valid_n(const char *str, size_t len_bytes) _pure_;
|
|
|
|
static inline char *utf8_is_valid(const char *s) {
|
|
|
|
return utf8_is_valid_n(s, (size_t) -1);
|
|
|
|
}
|
2012-03-12 22:22:16 +01:00
|
|
|
char *ascii_is_valid(const char *s) _pure_;
|
2018-06-09 13:41:24 +02:00
|
|
|
char *ascii_is_valid_n(const char *str, size_t len);
|
2012-03-12 22:22:16 +01:00
|
|
|
|
2020-07-30 17:08:39 +02:00
|
|
|
bool utf8_is_printable_newline(const char* str, size_t length, bool allow_newline) _pure_;
|
2014-12-04 02:36:04 +01:00
|
|
|
#define utf8_is_printable(str, length) utf8_is_printable_newline(str, length, true)
|
|
|
|
|
|
|
|
char *utf8_escape_invalid(const char *s);
|
2019-05-15 10:57:07 +02:00
|
|
|
char *utf8_escape_non_printable_full(const char *str, size_t console_width);
|
|
|
|
static inline char *utf8_escape_non_printable(const char *str) {
|
|
|
|
return utf8_escape_non_printable_full(str, (size_t) -1);
|
|
|
|
}
|
2012-07-13 01:07:41 +02:00
|
|
|
|
2015-12-13 23:26:43 +01:00
|
|
|
size_t utf8_encode_unichar(char *out_utf8, char32_t g);
|
2018-06-25 19:17:42 +02:00
|
|
|
size_t utf16_encode_unichar(char16_t *out, char32_t c);
|
|
|
|
|
2018-06-25 19:16:43 +02:00
|
|
|
char *utf16_to_utf8(const char16_t *s, size_t length /* bytes! */);
|
2018-06-25 19:17:42 +02:00
|
|
|
char16_t *utf8_to_utf16(const char *s, size_t length);
|
|
|
|
|
2018-09-27 17:13:53 +02:00
|
|
|
size_t char16_strlen(const char16_t *s); /* returns the number of 16bit words in the string (not bytes!) */
|
2013-09-17 21:39:09 +02:00
|
|
|
|
2019-02-26 12:37:40 +01:00
|
|
|
int utf8_encoded_valid_unichar(const char *str, size_t length);
|
2015-12-13 23:26:43 +01:00
|
|
|
int utf8_encoded_to_unichar(const char *str, char32_t *ret_unichar);
|
2014-12-22 12:57:05 +01:00
|
|
|
|
2015-12-13 23:26:43 +01:00
|
|
|
static inline bool utf16_is_surrogate(char16_t c) {
|
2018-07-18 12:23:31 +02:00
|
|
|
return c >= 0xd800U && c <= 0xdfffU;
|
2014-12-22 12:57:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-13 23:26:43 +01:00
|
|
|
static inline bool utf16_is_trailing_surrogate(char16_t c) {
|
2018-07-18 12:23:31 +02:00
|
|
|
return c >= 0xdc00U && c <= 0xdfffU;
|
2014-12-22 12:57:05 +01:00
|
|
|
}
|
|
|
|
|
2015-12-13 23:26:43 +01:00
|
|
|
static inline char32_t utf16_surrogate_pair_to_unichar(char16_t lead, char16_t trail) {
|
2018-07-18 12:23:31 +02:00
|
|
|
return ((((char32_t) lead - 0xd800U) << 10) + ((char32_t) trail - 0xdc00U) + 0x10000U);
|
2014-12-22 12:57:05 +01:00
|
|
|
}
|
2018-02-14 18:41:03 +01:00
|
|
|
|
|
|
|
size_t utf8_n_codepoints(const char *str);
|
2018-04-11 19:50:53 +02:00
|
|
|
size_t utf8_console_width(const char *str);
|