YSTest: CharacterMapping.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

CharacterMapping.h
浏览该文件的文档.
1 /*
2 © 2009-2015 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>
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 inline PDefH(char16_t, FetchBiCharBE, const char* c_ptr)
80 ImplRet(yconstraint(c_ptr), char16_t((*c_ptr << CHAR_BIT) | c_ptr[1]))
81
82 inline PDefH(char16_t, FetchBiCharLE, const char* c_ptr)
84 ImplRet(yconstraint(c_ptr), char16_t((c_ptr[1] << CHAR_BIT) | *c_ptr))
86
87
92 enum class ConversionResult
93 {
94 OK = 0,
95 BadState,
96 BadSource,
97 Invalid,
98 Unhandled
99 };
100
101
106 struct ConversionState
107 {
112 std::uint_fast8_t Index;
113 union
114 {
115 ucsint_t Wide;
117 char32_t UCS4;
122 byte Sequence[sizeof(ucsint_t)];
123 } Value;
124
125 yconstfn
126 ConversionState(size_t n = 0)
127 : Index(std::uint_fast8_t(n)), Value()
128 {}
129 };
130
132
133 yconstfn PDefH(std::uint_fast8_t&, GetIndexOf, ConversionState& st)
135 ImplRet(st.Index)
136 yconstfn PDefH(ucsint_t&, GetWideOf, ConversionState& st)
137 ImplRet(st.Value.Wide)
138 yconstfn PDefH(byte*, GetSequenceOf, ConversionState& st)
139 ImplRet(st.Value.Sequence)
141
142
147 template<typename _type>
148 yconstfn _type&
149 GetIndexOf(_type& st)
150 {
151 return st;
152 }
153
154
161 YF_API YB_STATELESS size_t
162 FetchFixedCharWidth(Encoding);
163
170 YF_API YB_STATELESS size_t
171 FetchMaxCharWidth(Encoding);
172
179 YF_API YB_STATELESS size_t
180 FetchMaxVariantCharWidth(Encoding);
181
182
184 template<typename _tIn>
185 using GuardPair = std::pair<ystdex::lref<_tIn>, const _tIn>;
186
187 } // namespace CHRLib;
188
189 #endif
190
CHRLib::ConversionState
编码转换状态。
Definition: CharacterMapping.h:106
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:522
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
CHRLib::FetchBiCharLE
FetchBiCharLE
Definition: CharacterMapping.h:83
CHRLib::GuardPair
std::pair< ystdex::lref< _tIn >, const _tIn > GuardPair
Definition: CharacterMapping.h:185
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:82
CHRLib::Encoding
std::FILE Encoding
Definition: CharacterProcessing.h:89
cassert.h
ISO C 断言/调试跟踪扩展。
CHRLib::ConversionState::Wide
ucsint_t Wide
Definition: CharacterMapping.h:115
CHRLib::ConversionState::Index
std::uint_fast8_t Index
当前状态索引。
Definition: CharacterMapping.h:112
CHRLib::CharSet::UTF_8
yconstexpr const Encoding UTF_8(csUTF8)
ref.hpp
引用包装。
YSLib::Drawing::char32_t
tr TextRegion &tr char32_t
Definition: TextLayout.h:92
CHRLib::CS_Default
yconstexpr const Encoding CS_Default(CharSet::UTF_8)
默认字符编码。
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:58
CHRLib::ConversionState::Sequence
byte Sequence[sizeof(ucsint_t)]
字节序列：宽字符的字节表示。
Definition: CharacterMapping.h:122
CHRLib::char16_t
char16_t((*c_ptr<< CHAR_BIT)|c_ptr[1])) inline PDefH(char16_t
取 c_ptr 指向的小端序双字节字符。
CHRLib::FetchFixedCharWidth
YF_API YB_STATELESS size_t FetchFixedCharWidth(Encoding)
取指定固定编码的固定字符宽度。
Definition: chrmap.cpp:37
std
Definition: memory.hpp:1100
CHRLib::ucsint_t
std::char_traits< char32_t >::int_type ucsint_t
UCS 整数类型。
Definition: CharacterDefinition.h:47
CHRLib::PDefH
PDefH(char16_t, FetchBiCharBE, const char *c_ptr) ImplRet(yconstraint(c_ptr)
取 c_ptr 指向的大端序双字节字符。
CHRLib::ConversionState::UCS4
char32_t UCS4
Definition: CharacterMapping.h:117
CHRLib::GetSequenceOf
yconstfn ConversionState &st GetSequenceOf
Definition: CharacterMapping.h:138
YModules.h
CHRLib
Definition: CharacterDefinition.h:38
ystdex::byte
unsigned char byte
字节类型。
Definition: ydef.h:808
CHRLib::FetchMaxVariantCharWidth
YF_API YB_STATELESS size_t FetchMaxVariantCharWidth(Encoding)
取指定变长编码的最大字符宽度。
Definition: chrmap.cpp:67
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:654
CHRLib::FetchMaxCharWidth
YF_API YB_STATELESS size_t FetchMaxCharWidth(Encoding)
取指定编码的最大字符宽度。
Definition: chrmap.cpp:59
YF_API
#define YF_API
Definition: Platform.h:56
CHRLib::ConversionState::Value
union CHRLib::ConversionState::@4 Value
CHRLib::MapFixedEncoding
取指定字符类型对应的默认定长编码。
Definition: CharacterMapping.h:58
CHRLib::ImplRet
const char *c_ptr ImplRet(yconstraint(c_ptr), char16_t((c_ptr[1]<< CHAR_BIT)|*c_ptr)) enum class ConversionResult
编码转换结果。
Definition: CharacterMapping.h:84
CHRLib::ConversionState::ConversionState
yconstfn ConversionState(size_t n=0)
Definition: CharacterMapping.h:126
CHRLib::GetWideOf
yconstfn GetWideOf
Definition: CharacterMapping.h:136
platform::n
size_t n
Definition: YCLib/FileSystem.cpp:321