2012-03-12 22:22:16 +01:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2012-03-12 22:22:16 +01:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2012 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2012-03-12 22:22:16 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2012-03-12 22:22:16 +01:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2012-03-12 22:22:16 +01:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2013-04-24 04:40:26 +02:00
|
|
|
#include <stdbool.h>
|
2015-11-01 04:39:15 +01:00
|
|
|
#include <uchar.h>
|
2013-04-24 04:40:26 +02:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
#include "macro.h"
|
|
|
|
|
2014-01-18 03:28:41 +01:00
|
|
|
#define UTF8_REPLACEMENT_CHARACTER "\xef\xbf\xbd"
|
|
|
|
|
2015-11-01 04:39:15 +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_;
|
|
|
|
|
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-11-01 04:39:15 +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-11-01 04:39:15 +01:00
|
|
|
char32_t utf8_encoded_to_unichar(const char *str);
|
2014-12-22 12:57:05 +01:00
|
|
|
|
2015-11-01 04:39:15 +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-11-01 04:39:15 +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-11-01 04:39:15 +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;
|
|
|
|
}
|