Mercurial > libunicode
annotate unicode.hpp @ 15:aa7817402878
unicode: update to 13.0.0
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 03 Feb 2021 16:04:02 +0100 |
parents | 153c09cc6dcb |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * unicode.hpp -- UTF-8 to UTF-32 conversions and various operations | |
3 * | |
14
153c09cc6dcb
misc: miscellaneous cleanups for 2021
David Demelier <markand@malikania.fr>
parents:
10
diff
changeset
|
4 * Copyright (c) 2013-2021 David Demelier <markand@malikania.fr> |
0 | 5 * |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef UNICODE_HPP | |
20 #define UNICODE_HPP | |
21 | |
22 #include <stdexcept> | |
23 #include <string> | |
7 | 24 #include <string_view> |
0 | 25 |
26 namespace unicode { | |
27 | |
6
d9c9a35cb4b2
Get rid of export macro, use CMake
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
28 void encode(char32_t point, char res[5]) noexcept; |
0 | 29 |
6
d9c9a35cb4b2
Get rid of export macro, use CMake
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
30 void decode(char32_t& c, const char* res) noexcept; |
0 | 31 |
7 | 32 auto nbytes_utf8(char c) noexcept -> int; |
0 | 33 |
7 | 34 auto nbytes_point(char32_t point) noexcept -> int; |
0 | 35 |
7 | 36 auto length(std::string_view str) -> unsigned; |
0 | 37 |
38 template <typename Func> | |
7 | 39 void for_each(std::string_view str, Func function) |
0 | 40 { |
9 | 41 for (size_t i = 0; i < str.size(); ) { |
42 char32_t point = 0; | |
43 int size = nbytes_utf8(str[i]); | |
0 | 44 |
9 | 45 if (size < 0) |
46 throw std::invalid_argument("invalid sequence"); | |
0 | 47 |
9 | 48 decode(point, str.data() + i); |
49 function(point); | |
0 | 50 |
9 | 51 i += size; |
52 } | |
0 | 53 } |
54 | |
7 | 55 auto to_utf8(std::u32string_view array) -> std::string; |
0 | 56 |
7 | 57 auto to_utf32(std::string_view str) -> std::u32string; |
0 | 58 |
7 | 59 auto isspace(char32_t c) noexcept -> bool; |
0 | 60 |
7 | 61 auto isdigit(char32_t c) noexcept -> bool; |
0 | 62 |
7 | 63 auto isalpha(char32_t c) noexcept -> bool; |
0 | 64 |
7 | 65 auto isupper(char32_t c) noexcept -> bool; |
0 | 66 |
7 | 67 auto islower(char32_t c) noexcept -> bool; |
0 | 68 |
7 | 69 auto istitle(char32_t c) noexcept -> bool; |
0 | 70 |
7 | 71 auto toupper(char32_t c) noexcept -> char32_t; |
0 | 72 |
7 | 73 auto tolower(char32_t c) noexcept -> char32_t; |
0 | 74 |
7 | 75 auto totitle(char32_t c) noexcept -> char32_t; |
0 | 76 |
7 | 77 auto toupper(std::u32string_view str) -> std::u32string; |
0 | 78 |
7 | 79 auto toupper(std::string_view str) -> std::string; |
0 | 80 |
7 | 81 auto tolower(std::u32string_view str) -> std::u32string; |
0 | 82 |
7 | 83 auto tolower(std::string_view str) -> std::string; |
0 | 84 |
85 } // !unicode | |
86 | |
87 #endif // !UNICODE_HPP |