YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
MapEx.h
浏览该文件的文档.
1 /*
2  © 2012-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_MapEx_h_
29 #define INC_CHRLib_MapEx_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_CHRLib_StaticMapping
33 
34 namespace CHRLib
35 {
36 
42 #define CHRLIB_NODYNAMIC_MAPPING 0
43 
44 #if CHRLIB_NODYNAMIC_MAPPING
45 
50 yconstexpr byte cp17[]{0};
51 extern "C"
52 {
53  extern const byte cp113[];
54  //extern const byte cp2026[13658];
55 }
58 #else
59 
67 extern byte* cp17;
68 extern byte* cp113;
69 extern byte* cp2026;
71 
72 #endif
73 
74 
80 template<>
81 struct GUCS2Mapper<CharSet::SHIFT_JIS>
82 {
83 #if 0
84  template<typename _tObj, typename _tIn, typename _tState>
85  static byte
86  Map(_tObj& uc, _tIn&& i, _tState&& st)
87  {
88  uint_least16_t row(0), col(0), ln(188); // (7E-40 + 1 + FC-80 + 1)
89  const auto c(FillByte(i, st));
90 
91  if((c >= 0xA1) && (c <= 0xC6))
92  {
93  const auto d(FillByte(i, st));
94 
95  row = c - 0xA1 ;
96  if(d >= 0x40 && d <= 0x7E)
97  col = d - 0x40 ;
98  else if(d >= 0xA1 && d <= 0xFE)
99  col = d - 0x62;
100  uc = cp17[row * ln + col];
101  }
102  else if(c >= 0xC9 && c <= 0xF9)
103  {
104  const auto d(FillByte(i, st));
105 
106  row = c - 0xA3;
107  if(d >= 0x40 && d <= 0x7E)
108  col = d - 0x40 ;
109  else if(d >= 0xA1 && d <= 0xFE)
110  col = d - 0x62;
111  uc = cp17[row * ln + col];
112  }
113  else if(c < 0x80)
114  {
115  uc = c;
116  return 1;
117  }
118  else
119  uc = 0xFFFE;
120  return 2;
121  }
122 #endif
123 };
124 
125 template<>
126 struct GUCS2Mapper<CharSet::GBK>
127 {
129  template<typename _tObj, typename _tIn, typename _tState>
130  static ConversionResult
131  Map(_tObj& uc, _tIn&& i, _tState&& st)
132  {
133  yassume(cp113);
134 
135  const auto seq(GetSequenceOf(st));
136 
137  switch(GetCountOf(st))
138  {
139  case 0:
140  if(YB_UNLIKELY(!FillByte(i, st)))
142  if(cp113[seq[0]] != 0)
143  {
144  uc = seq[0];
145  break;
146  }
147  case 1:
148  if(YB_UNLIKELY(!FillByte(i, st)))
150  if(YB_LIKELY((seq[0] << 8 | seq[1]) < 0xFF7E))
151  {
152  uc = reinterpret_cast<const ucs2_t*>(cp113 + 0x0100)[
153  seq[0] << 8 | seq[1]];
154  break;
155  }
157  default:
159  }
160  return ConversionResult::OK;
161  }
162 };
163 
164 template<>
165 struct GUCS2Mapper<CharSet::Big5>
166 {
167 /* template<typename _tObj, typename _tIn, typename _tState>
168  static byte
169  Map(_tObj& uc, _tIn&& i, _tState&& st)
170  {
171  uint_least16_t row(0), col(0), ln(157); // (7E-40 + FE-A1)
172  const auto c(FillByte(i, st));
173 
174  if(c >= 0xA1 && c <= 0xC6)
175  {
176  const auto d(FillByte(i, st));
177 
178  row = c - 0xA1;
179  if(d >= 0x40 && d <= 0x7E)
180  col = d - 0x40;
181  else if(d >= 0xA1 && d <= 0xFE)
182  col = d - 0x62;
183  uc = cp2026[row * ln + col];
184  return 2;
185  }
186  else if(c >= 0xC9 && c <= 0xF9)
187  {
188  const auto d(FillByte(i, st));
189 
190  row = c - 0xA3;
191  if(d >= 0x40 && d <= 0x7E)
192  col = c - 0x40;
193  else if(d >= 0xA1 && d <= 0xFE)
194  col = d - 0x62;
195  uc = cp2026[row * ln + col];
196  return 2;
197  }
198  else if(c < 0x80)
199  {
200  uc = c;
201  return 1;
202  }
203  else
204  uc = 0xFFFE;
205  return 2;
206  }*/
207 };
209 
210 
215 template<typename _fCodemapTransform>
216 _fCodemapTransform*
218 {
219  using namespace CharSet;
220 
221 #define CHR_MapItem(enc) \
222 case enc: \
223  return UCS2Mapper<enc>;
224 
225  switch(enc)
226  {
233  default:
234  break;
235  }
236 #undef CHR_MapItem
237  return {};
238 }
239 
240 } // namespace CHRLib;
241 
242 #endif
243 
ConversionResult
编码转换结果。
Definition: chrmap.h:75
yconstexpr Encoding UTF_16LE(csUTF16LE)
bool FillByte(_tIn &i, _tState &st)
以输入迭代器指向内容填充有效输入迭代器指定的字节。
Definition: smap.hpp:45
yconstexpr Encoding UTF_16BE(csUTF16BE)
静态编码映射模板及 Unicode 编码特化。
Definition: smap.hpp:68
unsigned char byte
字节类型。
Definition: ydef.h:555
#define YB_UNLIKELY(expr)
分支预测提示。
Definition: ydef.h:298
源数据不可达(如越界)。
#define yassume
假定:环境语义。
Definition: cassert.h:58
byte * cp17
动态加载的编码转换表。
Definition: MapEx.cpp:38
yconstexpr Encoding GBK(csGBK)
yconstexpr Encoding Big5(csBig5)
< 仅 EUC-CN ,GB2312 最常用实现。
char16_t ucs2_t
UCS-2 字符类型。
Definition: chrdef.h:44
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
static ConversionResult Map(_tObj &uc, _tIn &&i, _tState &&st)
Definition: MapEx.h:131
byte * cp113
Definition: MapEx.cpp:39
yconstexpr Encoding SHIFT_JIS(csShiftJIS)
#define YB_LIKELY(expr)
Definition: ydef.h:297
yconstexpr Encoding UTF_8(csUTF8)
未处理(超过被处理的界限)。
_fCodemapTransform * FetchMapperPtr(Encoding enc)
取指定编码映射的转换函数指针。
Definition: MapEx.h:217
#define CHR_MapItem(enc)
byte * cp2026
Definition: MapEx.cpp:40