2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
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"
|
2015-12-13 23:26:43 +01:00
|
|
|
#include "missing.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
|
|
|
|
2013-09-18 17:52:14 +02:00
|
|
|
const char *utf8_is_valid(const char *s) _pure_;
|
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
|
|
|
|
2014-03-31 14:57:28 +02:00
|
|
|
bool utf8_is_printable_newline(const char* str, size_t length, bool 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);
|
|
|
|
char *utf8_escape_non_printable(const char *str);
|
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);
|
2013-01-19 04:20:23 +01:00
|
|
|
char *utf16_to_utf8(const void *s, size_t length);
|
2013-09-17 21:39:09 +02:00
|
|
|
|
|
|
|
int utf8_encoded_valid_unichar(const char *str);
|
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) {
|
2014-12-22 12:57:05 +01:00
|
|
|
return (0xd800 <= c && c <= 0xdfff);
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:26:43 +01:00
|
|
|
static inline bool utf16_is_trailing_surrogate(char16_t c) {
|
2014-12-22 12:57:05 +01:00
|
|
|
return (0xdc00 <= c && c <= 0xdfff);
|
|
|
|
}
|
|
|
|
|
2015-12-13 23:26:43 +01:00
|
|
|
static inline char32_t utf16_surrogate_pair_to_unichar(char16_t lead, char16_t trail) {
|
2014-12-22 12:57:05 +01:00
|
|
|
return ((lead - 0xd800) << 10) + (trail - 0xdc00) + 0x10000;
|
|
|
|
}
|
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);
|