YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
chrmap.h
浏览该文件的文档.
1 /*
2  © 2009-2014 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_chrmap_h_
29 #define INC_CHRLib_chrmap_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_CHRLib_Encoding
33 #include <ystdex/cassert.h>
34 
35 namespace CHRLib
36 {
37 
38 using CharSet::Encoding;
39 
40 
46 
47 
52 inline ucs2_t
53 FetchBiCharBE(const char* c_ptr)
54 {
55  yconstraint(c_ptr);
56  return (*c_ptr << CHAR_BIT) | c_ptr[1];
57 }
58 
63 inline ucs2_t
64 FetchBiCharLE(const char* c_ptr)
65 {
66  yconstraint(c_ptr);
67  return (c_ptr[1] << CHAR_BIT) | *c_ptr;
68 }
69 
70 
75 enum class ConversionResult
76 {
77  OK = 0,
78  BadState,
79  BadSource,
80  Invalid,
81  Unhandled
82 };
83 
84 
90 {
94  std::uint_fast8_t Count;
95  union
96  {
103  } Value;
104 
105  yconstfn
106  ConversionState(size_t n= 0)
107  : Count(n), Value()
108  {}
109 };
110 
112 
113 yconstfn std::uint_fast8_t&
115 {
116  return st.Count;
117 }
119 GetWideOf(ConversionState& st)
120 {
121  return st.Value.Wide;
122 }
123 yconstfn byte*
124 GetSequenceOf(ConversionState& st)
125 {
126  return st.Value.Sequence;
127 }
129 
130 
135 template<typename _type>
136 yconstfn _type&
137 GetCountOf(_type& st)
138 {
139  return st;
140 }
141 
142 
149 YF_API size_t
151 
158 YF_API size_t
160 
167 YF_API size_t
169 
170 } // namespace CHRLib;
171 
172 #endif
173 
union CHRLib::ConversionState::@0 Value
ConversionResult
编码转换结果。
Definition: chrmap.h:75
yconstfn std::uint_fast8_t & GetCountOf(ConversionState &st)
Definition: chrmap.h:114
yconstexpr Encoding CS_Default
默认字符编码。
Definition: chrmap.h:45
编码转换状态。
Definition: chrmap.h:89
std::uint_fast8_t Count
当前已转换字符计数。
Definition: chrmap.h:94
#define YF_API
Definition: Platform.h:64
ucs2_t FetchBiCharBE(const char *c_ptr)
取 c_ptr 指向的大端序双字节字符。
Definition: chrmap.h:53
unsigned char byte
字节类型。
Definition: ydef.h:555
ISO C 断言/调试跟踪扩展。
数据校验失败(如不构成代码点的字节序列)。
yconstfn _type & GetCountOf(_type &st)
一般类型计数。
Definition: chrmap.h:137
yconstfn ConversionState(size_t n=0)
Definition: chrmap.h:106
源数据不可达(如越界)。
YF_API size_t FetchMaxVariantCharWidth(Encoding)
取指定变长编码的最大字符宽度。
Definition: chrmap.cpp:67
#define yconstraint
约束:接口语义。
Definition: cassert.h:47
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
YF_API size_t FetchFixedCharWidth(Encoding)
取指定固定编码的固定字符宽度。
Definition: chrmap.cpp:37
char16_t ucs2_t
UCS-2 字符类型。
Definition: chrdef.h:44
YF_API size_t FetchMaxCharWidth(Encoding)
取指定编码的最大字符宽度。
Definition: chrmap.cpp:59
ucs2_t FetchBiCharLE(const char *c_ptr)
取 c_ptr 指向的小端序双字节字符。
Definition: chrmap.h:64
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
byte Sequence[sizeof(ucsint_t)]
字节序列:宽字符的字节表示。
Definition: chrmap.h:102
yconstexpr Encoding UTF_8(csUTF8)
未处理(超过被处理的界限)。
std::char_traits< ucs4_t >::int_type ucsint_t
UCS 整数类型。
Definition: chrdef.h:46