YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
MapEx.h
浏览该文件的文档.
1 /*
2  Copyright (C) by Franksoft 2012.
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 CHRLIB_INC_MAPEX_H_
29 #define CHRLIB_INC_MAPEX_H_ 1
30 
31 #include "CHRLib/smap.hpp"
32 
34 
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 }
56 yconstexpr byte cp2026[] = {0};
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 /* template<typename _tObj, typename _tIn, typename _tState>
84  static byte
85  Map(_tObj& uc, _tIn&& i, _tState&& st)
86  {
87  uint_least16_t row(0), col(0), ln(188); // (7E-40 + 1 + FC-80 + 1)
88  const auto c(FillByte(i, st));
89 
90  if((c >= 0xA1) && (c <= 0xC6))
91  {
92  const auto d(FillByte(i, st));
93 
94  row = c - 0xA1 ;
95  if(d >= 0x40 && d <= 0x7E)
96  col = d - 0x40 ;
97  else if(d >= 0xA1 && d <= 0xFE)
98  col = d - 0x62;
99  uc = cp17[row * ln + col];
100  }
101  else if(c >= 0xC9 && c <= 0xF9)
102  {
103  const auto d(FillByte(i, st));
104 
105  row = c - 0xA3;
106  if(d >= 0x40 && d <= 0x7E)
107  col = d - 0x40 ;
108  else if(d >= 0xA1 && d <= 0xFE)
109  col = d - 0x62;
110  uc = cp17[row * ln + col];
111  }
112  else if(c < 0x80)
113  {
114  uc = c;
115  return 1;
116  }
117  else
118  uc = 0xFFFE;
119  return 2;
120  }*/
121 };
122 
123 template<>
124 struct GUCS2Mapper<CharSet::GBK>
125 {
126  template<typename _tObj, typename _tIn, typename _tState>
127  static ConversionResult
128  Map(_tObj& uc, _tIn&& i, _tState&& st)
129  {
130  yassume(cp113);
131 
132  const auto seq(GetSequenceOf(st));
133 
134  switch(GetCountOf(st))
135  {
136  case 0:
137  if(YB_UNLIKELY(!FillByte(i, st)))
138  return ConversionResult::BadSource;
139  if(cp113[seq[0]] != 0)
140  {
141  uc = seq[0];
142  break;
143  }
144  case 1:
145  if(YB_UNLIKELY(!FillByte(i, st)))
146  return ConversionResult::BadSource;
147  if(YB_LIKELY((seq[0] << 8 | seq[1]) < 0xFF7E))
148  {
149  uc = reinterpret_cast<const ucs2_t*>(cp113 + 0x0100)[
150  seq[0] << 8 | seq[1]];
151  break;
152  }
153  return ConversionResult::Unhandled;
154  default:
155  return ConversionResult::BadState;
156  }
157  return ConversionResult::OK;
158  }
159 };
160 
161 template<>
162 struct GUCS2Mapper<CharSet::Big5>
163 {
164 /* template<typename _tObj, typename _tIn, typename _tState>
165  static byte
166  Map(_tObj& uc, _tIn&& i, _tState&& st)
167  {
168  uint_least16_t row(0), col(0), ln(157); // (7E-40 + FE-A1)
169  const auto c(FillByte(i, st));
170 
171  if(c >= 0xA1 && c <= 0xC6)
172  {
173  const auto d(FillByte(i, st));
174 
175  row = c - 0xA1;
176  if(d >= 0x40 && d <= 0x7E)
177  col = d - 0x40;
178  else if(d >= 0xA1 && d <= 0xFE)
179  col = d - 0x62;
180  uc = cp2026[row * ln + col];
181  return 2;
182  }
183  else if(c >= 0xC9 && c <= 0xF9)
184  {
185  const auto d(FillByte(i, st));
186 
187  row = c - 0xA3;
188  if(d >= 0x40 && d <= 0x7E)
189  col = c - 0x40;
190  else if(d >= 0xA1 && d <= 0xFE)
191  col = d - 0x62;
192  uc = cp2026[row * ln + col];
193  return 2;
194  }
195  else if(c < 0x80)
196  {
197  uc = c;
198  return 1;
199  }
200  else
201  uc = 0xFFFE;
202  return 2;
203  }*/
204 };
206 
207 
212 template<typename _fCodemapTransform>
213 _fCodemapTransform*
215 {
216  using namespace CharSet;
217 
218 #define CHR_MapItem(enc) \
219 case enc: \
220  return UCS2Mapper<enc>;
221 
222  switch(enc)
223  {
230  default:
231  break;
232  }
233 
234 #undef CHR_MapItem
235 
236  return nullptr;
237 }
238 
240 
241 #endif
242