Mercurial > libunicode
diff unicode.hpp @ 16:b5bcb17b9115
misc: remove C++, add libunicode.3
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 06 Aug 2021 11:52:41 +0200 |
parents | aa7817402878 |
children | 6fa530cc1188 |
line wrap: on
line diff
--- a/unicode.hpp Wed Feb 03 16:04:02 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * unicode.hpp -- UTF-8 to UTF-32 conversions and various operations - * - * Copyright (c) 2013-2021 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef UNICODE_HPP -#define UNICODE_HPP - -#include <stdexcept> -#include <string> -#include <string_view> - -namespace unicode { - -void encode(char32_t point, char res[5]) noexcept; - -void decode(char32_t& c, const char* res) noexcept; - -auto nbytes_utf8(char c) noexcept -> int; - -auto nbytes_point(char32_t point) noexcept -> int; - -auto length(std::string_view str) -> unsigned; - -template <typename Func> -void for_each(std::string_view str, Func function) -{ - for (size_t i = 0; i < str.size(); ) { - char32_t point = 0; - int size = nbytes_utf8(str[i]); - - if (size < 0) - throw std::invalid_argument("invalid sequence"); - - decode(point, str.data() + i); - function(point); - - i += size; - } -} - -auto to_utf8(std::u32string_view array) -> std::string; - -auto to_utf32(std::string_view str) -> std::u32string; - -auto isspace(char32_t c) noexcept -> bool; - -auto isdigit(char32_t c) noexcept -> bool; - -auto isalpha(char32_t c) noexcept -> bool; - -auto isupper(char32_t c) noexcept -> bool; - -auto islower(char32_t c) noexcept -> bool; - -auto istitle(char32_t c) noexcept -> bool; - -auto toupper(char32_t c) noexcept -> char32_t; - -auto tolower(char32_t c) noexcept -> char32_t; - -auto totitle(char32_t c) noexcept -> char32_t; - -auto toupper(std::u32string_view str) -> std::u32string; - -auto toupper(std::string_view str) -> std::string; - -auto tolower(std::u32string_view str) -> std::u32string; - -auto tolower(std::string_view str) -> std::string; - -} // !unicode - -#endif // !UNICODE_HPP