YSTest: YString.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YString.h
浏览该文件的文档.
1 /*
2 © 2010-2016, 2018-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 YSL_INC_Core_YString_h_
29 #define YSL_INC_Core_YString_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YObject // for allocator_arg;
33 #include YFM_YSLib_Adaptor_YTextBase // for u16string;
34
35 namespace YSLib
36 {
37
38 namespace Text
39 {
40
46 class YF_API String : public u16string
47 {
48 public:
52 DefDeCtor(String)
54
55 using u16string::u16string;
57 String(const u16string& s)
58 : u16string(s)
59 {}
61 String(u16string&& s)
62 : u16string(std::move(s))
63 {}
65
70 template<typename _tChar, yimpl(typename
72 = ystdex::enable_if_t<!std::is_same<_tChar, char16_t>::value>)>
73 YB_NONNULL(2)
74 String(const _tChar* s)
75 : u16string(MakeUCS2LE<u16string>(s, CS_Default))
76 {}
78 template<typename _tChar>
79 YB_NONNULL(2)
80 String(const _tChar* s, Encoding enc)
81 : u16string(MakeUCS2LE<u16string>(s, enc))
82 {}
84 template<typename _tChar, yimpl(typename
85 = ystdex::enable_if_t<!std::is_same<_tChar, char16_t>::value>)>
86 YB_NONNULL(2)
87 String(const _tChar* s, size_t n)
88 : String(basic_string_view<_tChar>(s, n), CS_Default)
89 {}
91 template<typename _tChar>
92 YB_NONNULL(2)
93 String(const _tChar* s, size_t n, Encoding enc)
94 : String(basic_string_view<_tChar>(s, n), enc)
95 {}
97
99 template<typename _tChar, yimpl(typename
101 = ystdex::enable_if_t<!std::is_same<_tChar, char16_t>::value>)>
102 explicit
103 String(basic_string_view<_tChar> sv)
104 : u16string(MakeUCS2LE<u16string>(sv, CS_Default))
105 {}
107 template<typename _tChar>
108 explicit
109 String(basic_string_view<_tChar> sv, Encoding enc)
110 : u16string(MakeUCS2LE<u16string>(sv, enc))
111 {}
113 template<typename _tChar, class _tTraits = std::char_traits<_tChar>,
114 class _tAlloc = std::allocator<_tChar>, yimpl(typename
115 = ystdex::enable_if_t<!std::is_same<_tChar, char16_t>::value>)>
116 String(const basic_string<_tChar, _tTraits, _tAlloc>& s)
117 : String(basic_string_view<_tChar>(s), CS_Default)
118 {}
120 template<typename _tChar, class _tTraits = std::char_traits<_tChar>,
121 class _tAlloc = std::allocator<_tChar>>
122 String(const basic_string<_tChar, _tTraits, _tAlloc>& s,
123 Encoding enc)
124 : String(basic_string_view<_tChar>(s), enc)
125 {}
127
129
133 template<typename _tChar, yimpl(typename
134 = ystdex::enable_if_t<!std::is_same<_tChar, char16_t>::value>)>
135 explicit
136 String(basic_string_view<_tChar> sv, const allocator_type& a)
137 : u16string(MakeUCS2LE<u16string>(std::allocator_arg, a, sv,
138 CS_Default))
139 {}
141 template<typename _tChar>
142 explicit
143 String(basic_string_view<_tChar> sv, Encoding enc, const allocator_type& a)
144 : u16string(MakeUCS2LE<u16string>(std::allocator_arg, a, sv, enc))
145 {}
147 template<typename _tChar, class _tTraits = std::char_traits<_tChar>,
148 class _tAlloc = std::allocator<_tChar>, yimpl(typename
149 = ystdex::enable_if_t<!std::is_same<_tChar, char16_t>::value>)>
150 String(const basic_string<_tChar, _tTraits, _tAlloc>& s,
151 const allocator_type& a)
152 : String(basic_string_view<_tChar>(s), CS_Default, a)
153 {}
155 template<typename _tChar, class _tTraits = std::char_traits<_tChar>,
156 class _tAlloc = std::allocator<_tChar>>
157 String(const basic_string<_tChar, _tTraits, _tAlloc>& s,
158 Encoding enc, const allocator_type& a)
159 : String(basic_string_view<_tChar>(s), enc, a)
160 {}
162
166 template<typename _tChar>
167 String(std::initializer_list<_tChar> il)
168 : u16string(il.begin(), il.end())
169 {}
173 DefDeCopyCtor(String)
177 DefDeMoveCtor(String)
178 DefDeDtor(String)
179
180
184 DefDeCopyAssignment(String)
189 DefDeMoveAssignment(String)
190
191
195 String&
196 operator*=(size_t);
197
199 friend DefSwap(ynothrow, String, ystdex::swap_dependent(
200 static_cast< u16string&>(_x), static_cast< u16string&>(_y)))
201
202
206 PDefH(string, GetMBCS, Encoding enc = CS_Default) const
207 ImplRet(MakeMBCS<string>(std::allocator_arg, get_allocator(), *this,
208 enc))
209 };
210
215 inline PDefHOp(String, *, const String& str, size_t n)
216 ImplRet(String(str) *= n)
217
218 } // namespace Text;
219
220 } // namespace YSLib;
221
222 #endif
223
DefDeCtor
#define DefDeCtor(_t)
简单通用成员函数定义。
Definition: YBaseMacro.h:157
YSLib::Text::String::String
String(u16string &&s)
构造：使用 YSLib 基本字符串右值引用。
Definition: YString.h:61
ystdex::cpp2017::basic_string
Definition: string.hpp:77
ystdex::cpp2017::basic_string_view
Definition: string_view.hpp:95
YSLib::Text::String::YB_NONNULL
YB_NONNULL(2) String(const _tChar *s)
构造：使用非 char16_t 的指针类型表示的 NTCTS 和默认编码。
Definition: YString.h:73
ystdex::cpp2017::u16string
basic_string< char16_t > u16string
Definition: string.hpp:773
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
YSLib::Text::YB_NONNULL
YB_ATTR_nodiscard YB_PURE YB_NONNULL(1, 2) inline PDefH(bool
检查第一参数是否具有指定的 BOM 。
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:59
YF_API
#define YF_API
Definition: Platform.h:56
CHRLib::MakeMBCS
YB_ATTR_nodiscard YB_PURE _tDst MakeMBCS(string_view sv, Encoding enc)
Definition: CharacterProcessing.h:744
ystdex::swap_dependent
void swap_dependent(_type &x, _type &y)(is_nothrow_swappable< _type >())
支持基于 ystdex_swap::swap 的 ADL 的左值交换。
Definition: swap.hpp:371
CHRLib::MakeUCS2LE
YB_ATTR_nodiscard YB_PURE _tDst MakeUCS2LE(basic_string_view< char > sv, _tParams &&... args)
Definition: CharacterProcessing.h:649
YSLib::Text::String::String
DefDeCtor(String) using u16string String(const u16string &s)
无参数构造：默认实现。
Definition: YString.h:57
YSLib::Text::String::DefSwap
friend DefSwap(ynothrow, String, ystdex::swap_dependent(static_cast< u16string & >(_x), static_cast< u16string & >(_y))) PDefH(string
取指定编码的多字节字符串。
DefDeDtor
#define DefDeDtor(_t)
Definition: YBaseMacro.h:177
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:47
ystdex::cpp2017::end
auto end(_tRange &c) -> decltype(c.end())
Definition: range.hpp:345
std
Definition: optional.h:982
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::Text::String::YB_NONNULL
YB_NONNULL(2) String(const _tChar *s
构造：使用指针表示的 NTCTS 和指定编码。
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:186
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
CHRLib::CS_Default
yconstexpr const Encoding CS_Default(CharSet::UTF_8)
默认字符编码。
YModules.h
YSLib 用户界面模块配置文件。
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:169
NPL::SXML::ParseOption::String
@ String
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YSLib::Text::ImplRet
YB_ATTR_nodiscard YB_PURE const char const char size_t n ImplRet(std::char_traits< char >::compare(Nonnull(buf), str, n)==0) template< size_t _vN > YB_ATTR_nodiscard YB_PURE YB_NONNULL(1) inline bool CheckBOM(const char *buf
CHRLib::enc
enc
Definition: CharacterProcessing.h:84
YSLib::Text::str
YB_ATTR_nodiscard YB_PURE const char const char * str
Definition: TextFile.h:83
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:191
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
ystdex::cpp2017::begin
auto begin(_tRange &c) -> decltype(c.begin())
Definition: range.hpp:323
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168