YSTest: string.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

string.h
浏览该文件的文档.
1 /*
2 © 2012-2015, 2017, 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
33 #ifndef YB_INC_libdefect_string_h_
34 #define YB_INC_libdefect_string_h_ 1
35
36 #include <string>
37 #include <cwchar> // for std::vswprintf;
38 #include "cstdio.h" // for std::vsnprintf;
39
40 // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015.
41 // NOTE: Fixed @ 4.8 for MinGW-W64.
42
43 #if defined(__GLIBCXX__) \
44 && (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L) \
45 && !(defined(_GLIBCXX_USE_C99) || defined(_GLIBCXX_USE_C99_STDLIB)) \
46 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
47
48 # include <ext/string_conversions.h>
49
50 namespace std _GLIBCXX_VISIBILITY(default)
51 {
52
53 # if !(defined(_GLIBCXX_USE_C99) || defined(_GLIBCXX_USE_C99_STDLIB))
54
55 # ifndef __BIONIC__
56 extern "C" long long int
57 (strtoll)(const char* __restrict, char** __restrict, int) throw();
58 extern "C" unsigned long long int
59 (strtoull)(const char* __restrict, char** __restrict, int) throw();
60 using ::strtold;
61 # else
62 using ::strtoll;
65 using ::strtoull;
66 # endif
67
68 using ::strtof;
69 using ::wcstol;
70 using ::wcstoul;
71 using ::wcstod;
72 # ifndef __BIONIC__
73 using ::wcstoll;
74 using ::wcstoull;
75 using ::wcstof;
76 using ::wcstold;
77 # endif
78
79 # endif
80
81
82 _GLIBCXX_BEGIN_NAMESPACE_VERSION
83 # if _GLIBCXX_USE_CXX11_ABI
84 _GLIBCXX_BEGIN_NAMESPACE_CXX11
85 # endif
86
87 // 21.4 Numeric Conversions [string.conversions].
88
89 # define YB_LibDefect_String_stoi(_s, _n, _t, _cfname) \
90 inline _t \
91 _n(const _s& __str, size_t* __idx = {}, int __base = 10) \
92 { \
93 return __gnu_cxx::__stoa(&_cfname, #_n, __str.c_str(), __idx, __base); \
94 }
95
96 inline int
97 stoi(const string& __str, size_t* __idx = {}, int __base = 10)
98 {
99 return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
100 __idx, __base);
101 }
102 YB_LibDefect_String_stoi(string, stol, long, std::strtol)
103 YB_LibDefect_String_stoi(string, stoul, unsigned long, std::strtoul)
104 YB_LibDefect_String_stoi(string, stoll, long long, std::strtoll)
105 YB_LibDefect_String_stoi(string, stoull, unsigned long long, std::strtoull)
106 # if defined(_GLIBCXX_USE_WCHAR_T) \
107 && (!defined(_GLIBCXX_USE_C99_WCHAR) || _GLIBCXX_USE_C99_WCHAR)
108 inline int
109 stoi(const wstring& __str, size_t* __idx = {}, int __base = 10)
110 {
111 return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
112 __idx, __base);
113 }
114 YB_LibDefect_String_stoi(wstring, stol, long, std::wcstol)
115 YB_LibDefect_String_stoi(wstring, stoul, unsigned long, std::wcstoul)
116 # ifndef __BIONIC__
117 YB_LibDefect_String_stoi(wstring, stoll, long long, std::wcstoll)
118 YB_LibDefect_String_stoi(wstring, stoull, unsigned long long, std::wcstoull)
119 # endif
120 # endif
121
122 # undef YB_LibDefect_String_stoi
123
124
125 # define YB_LibDefect_String_stof(_s, _n, _t, _cfname) \
126 inline _t \
127 _n(const _s& __str, size_t* __idx = {}) \
128 { \
129 return __gnu_cxx::__stoa(&_cfname, #_n, __str.c_str(), __idx); \
130 }
131
132 # if !(defined(__clang__) && defined(__BIONIC__))
133 // NOTE: Seems to be a bug of Clang++ 3.4.
134 // NOTE: strtof vs strtod.
135 YB_LibDefect_String_stof(string, stof, float, std::strtof)
136 YB_LibDefect_String_stof(string, stod, double, std::strtod)
137 # endif
138 # if !defined(__BIONIC__)
139 YB_LibDefect_String_stof(string, stold, long double, std::strtold)
140 # endif
141 # if defined(_GLIBCXX_USE_WCHAR_T) \
142 && (!defined(_GLIBCXX_USE_C99_WCHAR) || _GLIBCXX_USE_C99_WCHAR) \
143 && !defined(__BIONIC__)
144 // NOTE: wcstof vs wcstod.
145 YB_LibDefect_String_stof(wstring, stof, float, std::wcstof)
146 YB_LibDefect_String_stof(wstring, stod, double, std::wcstod)
147 YB_LibDefect_String_stof(wstring, stold, long double, std::wcstold)
148 # endif
149
150 # undef YB_LibDefect_String_stof
151
152
153 // NOTE: (v)snprintf vs sprintf.
154 # define YB_LibDefect_String_tostri(_s, _t, _fmt, _cfname) \
155 inline _s \
156 to_##_s(_t __val) \
157 { \
158 return __gnu_cxx::__to_xstring<_s>(&_cfname, \
159 sizeof(_t) * 4, _fmt, __val); \
160 }
161
162 // DR 1261.
163 YB_LibDefect_String_tostri(string, int, "%d", std::vsnprintf)
164 YB_LibDefect_String_tostri(string, unsigned, "%u", std::vsnprintf)
165 YB_LibDefect_String_tostri(string, long, "%ld", std::vsnprintf)
166 YB_LibDefect_String_tostri(string, unsigned long, "%lu", std::vsnprintf)
167 YB_LibDefect_String_tostri(string, long long, "%lld", std::vsnprintf)
168 YB_LibDefect_String_tostri(string, unsigned long long, "%llu", std::vsnprintf)
169 # if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) \
170 && defined(_GLIBCXX_USE_WCHAR_T) \
171 && (!defined(_GLIBCXX_USE_C99_WCHAR) || _GLIBCXX_USE_C99_WCHAR)
172 YB_LibDefect_String_tostri(wstring, int, L"%d", std::vswprintf)
173 YB_LibDefect_String_tostri(wstring, unsigned, L"%u", std::vswprintf)
174 YB_LibDefect_String_tostri(wstring, long, L"%ld", std::vswprintf)
175 YB_LibDefect_String_tostri(wstring, unsigned long, L"%lu", std::vswprintf)
176 YB_LibDefect_String_tostri(wstring, long long, L"%lld", std::vswprintf)
177 YB_LibDefect_String_tostri(wstring, unsigned long long, L"%llu", std::vswprintf)
178 # endif
179
180 # undef YB_LibDefect_String_tostri
181
182
183 # define YB_LibDefect_String_tostrf(_s, _t, _fmt, _cfname) \
184 inline _s \
185 to_##_s(_t __val) \
186 { \
187 return __gnu_cxx::__to_xstring<_s>(&_cfname, \
188 __gnu_cxx::__numeric_traits<_t>::__max_exponent10 + 20, \
189 _fmt, double(__val)); \
190 }
191
192 YB_LibDefect_String_tostrf(string, float, "%f", std::vsnprintf)
193 YB_LibDefect_String_tostrf(string, double, "%f", std::vsnprintf)
194 YB_LibDefect_String_tostrf(string, long double, "%f", std::vsnprintf)
195 # if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) \
196 && defined(_GLIBCXX_USE_WCHAR_T) \
197 && (!defined(_GLIBCXX_USE_C99_WCHAR) || _GLIBCXX_USE_C99_WCHAR)
198 YB_LibDefect_String_tostrf(wstring, float, L"%f", std::vswprintf)
199 YB_LibDefect_String_tostrf(wstring, double, L"%f", std::vswprintf)
200 YB_LibDefect_String_tostrf(wstring, long double, L"%f", std::vswprintf)
201 # endif
202
203 # undef YB_LibDefect_String_tostrf
204
205 # if _GLIBCXX_USE_CXX11_ABI
206 _GLIBCXX_END_NAMESPACE_CXX11
207 # endif
208 _GLIBCXX_END_NAMESPACE_VERSION
209
210 } // namespace std;
211
212 #endif /* ... __GXX_EXPERIMENTAL_CXX0X__ ... */
213
214 #endif
215
YSLib::IO::int
YF_API int
Definition: File.h:51
std
Definition: optional.h:982
platform::KeyCodes::DS::L
@ L
Definition: Keys.h:228
ystdex::cpp2017::wstring
basic_string< wchar_t > wstring
Definition: string.hpp:775
cstdio.h
ISO C 标准输入/输出扩展。