YSTest: Convert.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Convert.hpp
浏览该文件的文档.
1 /*
2 © 2013, 2015, 2019 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_Convert_hpp
29 #define INC_CHRLib_Convert_hpp 1
30
31 #include "YModules.h"
32 #include YFM_CHRLib_CharacterMapping
33 #include <ystdex/any_iterator.hpp> // for ystdex::input_monomorphic_iterator;
34
35 namespace CHRLib
36 {
37
39 template<typename _tIn, typename _tOut, typename _fConv>
40 ConversionResult
41 ConvertCharacter(_fConv f, _tOut&& obj, _tIn&& i, ConversionState&& st)
42 {
43 return f(yforward(obj), ystdex::input_monomorphic_iterator(std::ref(i)),
44 std::move(st));
45 }
47 template<typename _tIn, typename _fConv>
48 ConversionResult
49 ConvertCharacter(_fConv f, _tIn&& i, ConversionState&& st)
50 {
51 return f(ystdex::input_monomorphic_iterator(std::ref(i)), std::move(st));
52 }
54 template<typename _tIn, typename _tOut, typename _fConv>
55 ConversionResult
56 ConvertCharacter(_fConv f, _tOut&& obj, GuardPair<_tIn>& i,
57 ConversionState&& st)
58 {
59 ystdex::input_monomorphic_iterator it(i.first);
60
61 return f(yforward(obj), GuardPair<ystdex::input_monomorphic_iterator>(it,
62 i.second), std::move(st));
63 }
65 template<typename _tIn, typename _fConv>
66 ConversionResult
67 ConvertCharacter(_fConv f, GuardPair<_tIn>& i, ConversionState&& st)
68 {
69 ystdex::input_monomorphic_iterator it(i.first);
70
71 return f(GuardPair<ystdex::input_monomorphic_iterator>(it, i.second),
72 std::move(st));
73 }
74
82 template<typename _tIn>
83 bool
84 VerifyUC(_tIn&& first, ystdex::remove_reference_t<_tIn> last, Encoding enc)
85 {
86 auto res(ConversionResult::OK);
87
88 while(first != last && *first != 0
89 && (res = MBCToUC(first, enc), res == ConversionResult::OK))
90 ;
91 return res == ConversionResult::OK || *first == char();
92 }
98 template<typename _tIn>
99 bool
100 VerifyUC(_tIn&& first, typename std::iterator_traits<ystdex::decay_t<_tIn>>
101 ::difference_type n, Encoding enc)
102 {
103
104 if(n != 0)
105 {
106 auto res(ConversionResult::OK);
107 const auto i(first);
108
109 while(*first != 0 && (res = MBCToUC(first, first + n, enc),
110 res == ConversionResult::OK))
111 ;
112 return res == ConversionResult::OK
113 || (res == ConversionResult::BadSource && first - i == n)
114 || *first == char();
115 }
116 return true;
117 }
119
120 } // namespace CHRLib;
121
122 #endif
123
CHRLib::ConvertCharacter
ConversionResult ConvertCharacter(_fConv f, _tOut &&obj, _tIn &&i, ConversionState &&st)
Definition: Convert.hpp:41
CHRLib::ConversionState
编码转换状态。
Definition: CharacterMapping.h:109
CHRLib
Definition: CharacterDefinition.h:39
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:59
ystdex::any_input_iterator
动态泛型输入迭代器。
Definition: any_iterator.hpp:247
CHRLib::f
f(d, s)
ystdex::cpp2014::decay_t
typename decay< _type >::type decay_t
Definition: meta.hpp:196
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
any_iterator.hpp
动态泛型迭代器。
YSLib::i
return i
Definition: YCoreUtilities.h:177
CHRLib::MBCToUC
MBCToUC
Definition: CharacterProcessing.h:112
YModules.h
YSLib 用户界面模块配置文件。
CHRLib::VerifyUC
bool VerifyUC(_tIn &&first, ystdex::remove_reference_t< _tIn > last, Encoding enc)
验证指定字符序列是否可转换为 UCS-2 字符串。
Definition: Convert.hpp:84
CHRLib::enc
enc
Definition: CharacterProcessing.h:84
ystdex::cpp2014::remove_reference_t
typename remove_reference< _type >::type remove_reference_t
Definition: meta.hpp:155
ystdex::ref
void ref(const _type &&)=delete
CHRLib::GuardPair
std::pair< ystdex::lref< _tIn >, const _tIn > GuardPair
Definition: CharacterMapping.h:190