YSTest: CharacterMapping.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

CharacterMapping.h
浏览该文件的文档.
1 /*
2 © 2009-2015, 2019 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef INC_CHRLib_CharacterMapping_h_
29 #define INC_CHRLib_CharacterMapping_h_ 1
30
31 #include "YModules.h"
32 #include YFM_CHRLib_Encoding
33 #include YFM_YBaseMacro
34 #include <ystdex/cassert.h> // for yconstraint;
35 #include <utility> // for std::pair;
36 #include <ystdex/ref.hpp> // for ystdex::lref;
37
38 namespace CHRLib
39 {
40
41 using CharSet::Encoding;
42
43
48 yconstexpr const Encoding CS_Default(CharSet::UTF_8);
49
50
57 template<typename _tChar>
58 struct MapFixedEncoding : std::integral_constant<Encoding, CS_Default>
59 {};
60
61 template<>
62 struct MapFixedEncoding<char16_t>
63 : std::integral_constant<Encoding, CharSet::csUnicode>
64 {};
65
66 template<>
67 struct MapFixedEncoding<char32_t>
68 : std::integral_constant<Encoding, CharSet::csUCS4>
69 {};
71
72
78 YB_ATTR_nodiscard YB_PURE inline
80 PDefH(char16_t, FetchBiCharBE, const char* c_ptr)
81 ImplRet(yconstraint(c_ptr), char16_t((*c_ptr << CHAR_BIT) | c_ptr[1]))
82
84 YB_ATTR_nodiscard YB_PURE inline
85 PDefH(char16_t, FetchBiCharLE, const char* c_ptr)
86 ImplRet(yconstraint(c_ptr), char16_t((c_ptr[1] << CHAR_BIT) | *c_ptr))
88
89
94 enum class ConversionResult
95 {
96 OK = 0,
97 BadState,
98 BadSource,
99 Invalid,
100 Unhandled
101 };
102
103
108 struct ConversionState
109 {
114 std::uint_fast8_t Index;
115 union
116 {
117 ucsint_t Wide;
119 char32_t UCS4;
124 byte Sequence[sizeof(ucsint_t)];
125 } Value;
126
127 yconstfn
128 ConversionState(size_t n = 0)
129 : Index(std::uint_fast8_t(n)), Value()
130 {}
131 };
132
134
135 YB_ATTR_nodiscard YB_PURE yconstfn
137 PDefH(std::uint_fast8_t&, GetIndexOf, ConversionState& st)
138 ImplRet(st.Index)
139 YB_ATTR_nodiscard YB_PURE yconstfn
140 PDefH(ucsint_t&, GetWideOf, ConversionState& st)
141 ImplRet(st.Value.Wide)
142 YB_ATTR_nodiscard YB_PURE yconstfn
143 PDefH(byte*, GetSequenceOf, ConversionState& st)
144 ImplRet(st.Value.Sequence)
146
147
152 template<typename _type>
153 yconstfn _type&
154 GetIndexOf(_type& st)
155 {
156 return st;
157 }
158
159
166 YF_API YB_STATELESS size_t
167 FetchFixedCharWidth(Encoding);
168
175 YF_API YB_STATELESS size_t
176 FetchMaxCharWidth(Encoding);
177
184 YF_API YB_STATELESS size_t
185 FetchMaxVariantCharWidth(Encoding);
186
187
189 template<typename _tIn>
190 using GuardPair = std::pair<ystdex::lref<_tIn>, const _tIn>;
191
192 } // namespace CHRLib;
193
194 #endif
195
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
CHRLib::ConversionState
编码转换状态。
Definition: CharacterMapping.h:109
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
CHRLib::PDefH
YB_ATTR_nodiscard YB_PURE PDefH(char16_t, FetchBiCharBE, const char *c_ptr) ImplRet(yconstraint(c_ptr)
取 c_ptr 指向的大端序双字节字符。
ref.hpp
引用包装。
CHRLib::CharSet::UTF_8
yconstexpr const Encoding UTF_8(csUTF8)
CHRLib::MapFixedEncoding
取指定字符类型对应的默认定长编码。
Definition: CharacterMapping.h:59
CHRLib::ImplRet
YB_ATTR_nodiscard YB_PURE const char *c_ptr ImplRet(yconstraint(c_ptr), char16_t((c_ptr[1]<< CHAR_BIT)| *c_ptr)) enum class ConversionResult
编码转换结果。
Definition: CharacterMapping.h:86
CHRLib
Definition: CharacterDefinition.h:39
CHRLib::ConversionState::Sequence
byte Sequence[sizeof(ucsint_t)]
字节序列：宽字符的字节表示。
Definition: CharacterMapping.h:124
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:59
CHRLib::ConversionState::Wide
ucsint_t Wide
Definition: CharacterMapping.h:117
YF_API
#define YF_API
Definition: Platform.h:56
platform_ex::Windows::Invalid
@ Invalid
Definition: Win32/include/YCLib/MinGW32.h:485
CHRLib::ConversionState::Index
std::uint_fast8_t Index
当前状态索引。
Definition: CharacterMapping.h:114
CHRLib::ConversionState::ConversionState
yconstfn ConversionState(size_t n=0)
Definition: CharacterMapping.h:128
CHRLib::FetchMaxVariantCharWidth
YF_API YB_STATELESS size_t FetchMaxVariantCharWidth(Encoding)
取指定变长编码的最大字符宽度。
Definition: chrmap.cpp:67
CHRLib::ConversionState::PDefH
#define PDefH(_t, _n,...)
CHRLib::GetWideOf
YB_ATTR_nodiscard YB_PURE yconstfn GetWideOf
Definition: CharacterMapping.h:140
CHRLib::ConversionState::UCS4
char32_t UCS4
Definition: CharacterMapping.h:119
CHRLib::Encoding
std::FILE Encoding
Definition: CharacterProcessing.h:92
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
std
Definition: optional.h:982
CHRLib::FetchFixedCharWidth
YF_API YB_STATELESS size_t FetchFixedCharWidth(Encoding)
取指定固定编码的固定字符宽度。
Definition: chrmap.cpp:37
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:125
NPL::A1::Forms::Sequence
YF_API ReductionStatus Sequence(TermNode &, ContextNode &)
序列有序参数规约：移除第一项后顺序规约子项，结果为最后一个子项的规约结果。
Definition: NPLA1Forms.cpp:2605
CHRLib::CS_Default
yconstexpr const Encoding CS_Default(CharSet::UTF_8)
默认字符编码。
YModules.h
YSLib 用户界面模块配置文件。
CHRLib::FetchBiCharLE
YB_ATTR_nodiscard YB_PURE FetchBiCharLE
Definition: CharacterMapping.h:85
CHRLib::char16_t
YB_ATTR_nodiscard YB_PURE char16_t((*c_ptr<< CHAR_BIT)|c_ptr[1])) YB_ATTR_nodiscard YB_PURE inline PDefH(char16_t
取 c_ptr 指向的小端序双字节字符。
CHRLib::ConversionState::Value
union CHRLib::ConversionState::@3 Value
CHRLib::GetSequenceOf
YB_ATTR_nodiscard YB_PURE yconstfn ConversionState &st GetSequenceOf
Definition: CharacterMapping.h:143
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
cassert.h
ISO C 断言/调试跟踪扩展。
CHRLib::ucsint_t
std::char_traits< char32_t >::int_type ucsint_t
UCS 整数类型。
Definition: CharacterDefinition.h:47
YSLib::Drawing::char32_t
YB_ATTR_nodiscard YB_PURE tr TextRegion &tr char32_t
Definition: TextLayout.h:93
CHRLib::FetchMaxCharWidth
YF_API YB_STATELESS size_t FetchMaxCharWidth(Encoding)
取指定编码的最大字符宽度。
Definition: chrmap.cpp:59
CHRLib::GuardPair
std::pair< ystdex::lref< _tIn >, const _tIn > GuardPair
Definition: CharacterMapping.h:190
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073