Mercurial > libunicode
view unicode.hpp @ 14:153c09cc6dcb
misc: miscellaneous cleanups for 2021
- Removal of Doxygen,
- Increase copyrights years,
- Replace bool with ints.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 03 Feb 2021 15:29:06 +0100 |
parents | ae1003c2a284 |
children |
line wrap: on
line source
/* * 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