YSTest: chrproc.h 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
chrproc.h
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2009 - 2013.
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_chrproc_h_
29 #define CHRLIB_INC_chrproc_h_ 1
30
31 #include "chrmap.h"
32 #include <cstdio>
33 #include <memory> // for std::move;
34 #include <ystdex/string.hpp> // for ystdex::string_traits;
35
36 CHRLIB_BEGIN
37
38 #if 0
39 size_t UTF16toUTF8(byte*, const u16*);
40 size_t UTF8toUTF16(u16*, const byte*);
41 bool u8cmp(char*, char*);
42 #endif
43
48 template<typename _tChar>
49 yconstfn bool
50 IsASCII(_tChar c)
51 {
52 return !(c & ~0x7F);
53 }
54
59 template<typename _tChar>
60 yconstfn char
61 ToASCII(_tChar c)
62 {
63 return c & 0x7F;
64 }
65
66
72 YF_API ConversionResult
73 MBCToUC(ucs2_t&, const char*&, Encoding, ConversionState&& = {});
74 inline ConversionResult
75 MBCToUC(ucs2_t& uc, const char*& c, Encoding enc, ConversionState& st)
76 {
77 return MBCToUC(uc, c, enc, std::move(st));
78 }
80
86 YF_API ConversionResult
87 MBCToUC(ucs2_t&, std::FILE*, Encoding, ConversionState&& = {});
88 inline ConversionResult
89 MBCToUC(ucs2_t& uc, std::FILE* fp, Encoding enc, ConversionState& st)
90 {
91 return MBCToUC(uc, fp, enc, std::move(st));
92 }
94
99 YF_API ConversionResult
100 MBCToUC(const char*&, Encoding, ConversionState&& = {});
101 inline ConversionResult
102 MBCToUC(const char*& c, Encoding enc, ConversionState& st)
103 {
104 return MBCToUC(c, enc, std::move(st));
105 }
107
108 YF_API ConversionResult
109 MBCToUC(std::FILE*, Encoding, ConversionState&& = {});
110 inline ConversionResult
111 MBCToUC(std::FILE* fp, Encoding enc, ConversionState& st)
112 {
113 return MBCToUC(fp, enc, std::move(st));
114 }
116
117
123 YF_API size_t
124 UCToMBC(char*, const ucs2_t&, Encoding);
125
126
132 YF_API size_t
133 MBCSToUCS2(ucs2_t*, const char*, Encoding = CS_Default);
134
140 YF_API size_t
141 UCS2ToMBCS(char*, const ucs2_t*, Encoding = CS_Default);
142
147 YF_API size_t
148 UCS4ToUCS2(ucs2_t*, const ucs4_t*);
149
154 template<class _tDst, class _tSrc>
155 _tDst
156 GetMBCSOf(const _tSrc& src, Encoding enc = CS_Default)
157 {
158 // FIXME: size for max MBC sequence length > 4;
159 _tDst str(src.length() << 2,
160 typename ystdex::string_traits<_tSrc>::value_type());
161
162 str.resize(UCS2ToMBCS(&str[0], src.c_str(), enc));
163 return str;
164 }
165
166
173 YF_API char*
174 strdup(const ucs2_t*, Encoding = CS_Default);
175
182 YF_API ucs2_t*
183 ucsdup(const char*, Encoding = CS_Default);
189 YF_API ucs2_t*
190 ucsdup(const ucs2_t*);
196 YF_API ucs2_t*
197 ucsdup(const ucs4_t*);
198
199 CHRLIB_END
200
201 #endif
202