Unicode Char
unicode_char.h
Go to the documentation of this file.
1 /* Copyright 2020 Zhao HG
2 
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software, and to permit persons to whom the Software is
8 furnished to do so, subject to the following conditions:
9 
10 The above copyright notice and this permission notice shall be included in all
11 copies or substantial portions of the Software.
12 
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 SOFTWARE. */
20 #ifndef INCLUDE_UNICODE_CHAR_H_
21 #define INCLUDE_UNICODE_CHAR_H_
22 
28 #include <iostream>
29 #include <vector>
30 #include <string>
31 #include <cstdint>
32 #include <utility>
33 
34 namespace unicode {
35 
36 using UChar = int32_t;
37 
39 enum class GeneralCategory {
40  Cc, Cf, Co, Cs, Ll, Lm, Lo, Lt, Lu, Mc,
41  Me, Mn, Nd, Nl, No, Pc, Pd, Pe, Pf, Pi,
42  Po, Ps, Sc, Sk, Sm, So, Zl, Zp, Zs
43 };
44 
46 enum class BaseGeneralCategory {
47  C, L, M, N, P, S, Z
48 };
49 
51 std::ostream& operator<<(std::ostream&, GeneralCategory);
53 std::ostream& operator<<(std::ostream&, BaseGeneralCategory);
54 
55 enum class BidirectionalCategory {
56  AL, AN, B, BN, CS, EN, ES, ET, FSI, L,
57  LRE, LRI, LRO, NSM, ON, PDF, PDI, R, RLE, RLI,
58  RLO, S, WS
59 };
60 
62 std::ostream& operator<<(std::ostream&, BidirectionalCategory);
63 
66  NO_MAPPING, CANONICAL, CIRCLE, COMPAT, FINAL, FONT, FRACTION, INITIAL, ISOLATED, MEDIAL,
67  NARROW, NOBREAK, SMALL, SQUARE, SUB, SUPER, VERTICAL, WIDE
68 };
69 
71 std::ostream& operator<<(std::ostream&, DecompositionMappingTag);
72 
74 GeneralCategory getGeneralCategory(UChar code);
76 BaseGeneralCategory getBaseGeneralCategory(UChar code);
77 
79 int32_t getCanonicalCombiningClass(UChar code);
80 
82 BidirectionalCategory getBidirectionalCategory(UChar code);
83 
85 DecompositionMappingTag getDecompositionMappingTag(UChar code);
87 std::vector<UChar> getDecompositionMapping(UChar code);
89 void getDecompositionMapping(UChar code, UChar buffer[]);
90 
95 int32_t getDecimalDigitValue(UChar code);
100 int32_t getDigitValue(UChar code);
105 double getNumericValue(UChar code);
110 std::pair<int64_t, int64_t> getNumericFraction(UChar code);
111 
113 bool isMirrored(UChar code);
114 
120 UChar getUpperCase(UChar code);
126 UChar getLowerCase(UChar code);
132 UChar getTitleCase(UChar code);
133 
135 std::string toUTF8(UChar code);
137 std::string toUTF8(const std::vector<UChar> codes);
139 UChar fromUTF8Char(const std::string& str);
141 std::vector<UChar> fromUTF8(const std::string& str);
142 
144 std::u16string toUTF16(const std::vector<UChar> codes);
146 std::vector<UChar> fromUTF16(const std::u16string& str);
147 
148 } // namespace unicode
149 
150 #endif // INCLUDE_UNICODE_CHAR_H_
unicode::BaseGeneralCategory
BaseGeneralCategory
Definition: unicode_char.h:46
unicode::DecompositionMappingTag
DecompositionMappingTag
Definition: unicode_char.h:65
unicode::GeneralCategory
GeneralCategory
Definition: unicode_char.h:39
unicode::operator<<
std::ostream & operator<<(std::ostream &, GeneralCategory)
Definition: general_category.cpp:24