YSTest: chrmap.h 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
chrmap.h
浏览该文件的文档.
1 ﻿/*
2 Copyright (C) by Franksoft 2009 - 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_CHRMAP_H_
29 #define CHRLIB_INC_CHRMAP_H_ 1
30
31 #include "encoding.h"
32
33 CHRLIB_BEGIN
34
35 using CharSet::Encoding;
36
37
42 yconstexpr Encoding CS_Default = CharSet::UTF_8;
43
44
49 inline ucs2_t
50 FetchBiCharBE(const char* c_ptr)
51 {
52 yconstraint(c_ptr);
53
54 return (*c_ptr << CHAR_BIT) | c_ptr[1];
55 }
56
61 inline ucs2_t
62 FetchBiCharLE(const char* c_ptr)
63 {
64 yconstraint(c_ptr);
65
66 return (c_ptr[1] << CHAR_BIT) | *c_ptr;
67 }
68
69
74 enum class ConversionResult
75 {
76 OK = 0,
77 BadState,
78 BadSource,
79 Invalid,
80 Unhandled
81 };
82
83
88 struct ConversionState
89 {
93 std::uint_fast8_t Count;
94 union
95 {
96 ucsint_t Wide;
97 byte Sequence[4];
98 } Value;
99
100 yconstfn
101 ConversionState(size_t n= 0)
102 : Count(n), Value()
103 {}
104 };
105
106 yconstfn std::uint_fast8_t&
107 GetCountOf(ConversionState& st)
108 {
109 return st.Count;
110 }
111 yconstfn ucsint_t&
112 GetWideOf(ConversionState& st)
113 {
114 return st.Value.Wide;
115 }
116 yconstfn byte*
117 GetSequenceOf(ConversionState& st)
118 {
119 return st.Value.Sequence;
120 }
121
122
127 template<typename _type>
128 yconstfn _type&
129 GetCountOf(_type& st)
130 {
131 return st;
132 }
133
134
141 YF_API size_t
142 FetchFixedCharWidth(Encoding);
143
150 YF_API size_t
151 FetchMaxCharWidth(Encoding);
152
159 YF_API size_t
160 FetchMaxVariantCharWidth(Encoding);
161
162 CHRLIB_END
163
164 #endif
165