YSTest: string.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

string.h
浏览该文件的文档.
1 /*
2 © 2012-2015 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>
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_HAVE_BROKEN_VSWPRINTF))
46
47 # include <ext/string_conversions.h>
48
49 namespace std _GLIBCXX_VISIBILITY(default)
50 {
51
52 # ifndef _GLIBCXX_USE_C99
53
54 # ifndef __BIONIC__
55 extern "C" long long int
56 (strtoll)(const char* __restrict, char** __restrict, int) throw();
57 extern "C" unsigned long long int
58 (strtoull)(const char* __restrict, char** __restrict, int) throw();
59 using ::strtold;
60 # else
61 using ::strtoll;
64 using ::strtoull;
65 # endif
66
67 using ::strtof;
68 using ::wcstol;
69 using ::wcstoul;
70 using ::wcstod;
71 # ifndef __BIONIC__
72 using ::wcstoll;
73 using ::wcstoull;
74 using ::wcstof;
75 using ::wcstold;
76 # endif
77
78 # endif
79
80
81 _GLIBCXX_BEGIN_NAMESPACE_VERSION
82
83 // 21.4 Numeric Conversions [string.conversions].
84
85 # define YB_LibDefect_String_stoi(_s, _n, _t, _cfname) \
86 inline _t \
87 _n(const _s& __str, size_t* __idx = {}, int __base = 10) \
88 { \
89 return __gnu_cxx::__stoa(&_cfname, #_n, __str.c_str(), __idx, __base); \
90 }
91
92 inline int
93 stoi(const string& __str, size_t* __idx = {}, int __base = 10)
94 {
95 return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
96 __idx, __base);
97 }
98 YB_LibDefect_String_stoi(string, stol, long, std::strtol)
99 YB_LibDefect_String_stoi(string, stoul, unsigned long, std::strtoul)
100 YB_LibDefect_String_stoi(string, stoll, long long, std::strtoll)
101 YB_LibDefect_String_stoi(string, stoull, unsigned long long, std::strtoull)
102 # ifdef _GLIBCXX_USE_WCHAR_T
103 inline int
104 stoi(const wstring& __str, size_t* __idx = {}, int __base = 10)
105 {
106 return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
107 __idx, __base);
108 }
109 YB_LibDefect_String_stoi(wstring, stol, long, std::wcstol)
110 YB_LibDefect_String_stoi(wstring, stoul, unsigned long, std::wcstoul)
111 # ifndef __BIONIC__
112 YB_LibDefect_String_stoi(wstring, stoll, long long, std::wcstoll)
113 YB_LibDefect_String_stoi(wstring, stoull, unsigned long long, std::wcstoull)
114 # endif
115 # endif
116
117 # undef YB_LibDefect_String_stoi
118
119
120 # define YB_LibDefect_String_stof(_s, _n, _t, _cfname) \
121 inline _t \
122 _n(const _s& __str, size_t* __idx = {}) \
123 { \
124 return __gnu_cxx::__stoa(&_cfname, #_n, __str.c_str(), __idx); \
125 }
126
127 # if !(defined(__clang__) && defined(__BIONIC__))
128 // NOTE: Seems to be a bug of Clang++ 3.4.
129 // NOTE: strtof vs strtod.
130 YB_LibDefect_String_stof(string, stof, float, std::strtof)
131 YB_LibDefect_String_stof(string, stod, double, std::strtod)
132 # endif
133 # if !defined(__BIONIC__)
134 YB_LibDefect_String_stof(string, stold, long double, std::strtold)
135 # endif
136 # if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__BIONIC__)
137 // NOTE: wcstof vs wcstod.
138 YB_LibDefect_String_stof(wstring, stof, float, std::wcstof)
139 YB_LibDefect_String_stof(wstring, stod, double, std::wcstod)
140 YB_LibDefect_String_stof(wstring, stold, long double, std::wcstold)
141 # endif
142
143 # undef YB_LibDefect_String_stof
144
145
146 // NOTE: (v)snprintf vs sprintf.
147 # define YB_LibDefect_String_tostri(_s, _t, _fmt, _cfname) \
148 inline _s \
149 to_##_s(_t __val) \
150 { \
151 return __gnu_cxx::__to_xstring<_s>(&_cfname, \
152 sizeof(_t) * 4, _fmt, __val); \
153 }
154
155 // DR 1261.
156 YB_LibDefect_String_tostri(string, int, "%d", std::vsnprintf)
157 YB_LibDefect_String_tostri(string, unsigned, "%u", std::vsnprintf)
158 YB_LibDefect_String_tostri(string, long, "%ld", std::vsnprintf)
159 YB_LibDefect_String_tostri(string, unsigned long, "%lu", std::vsnprintf)
160 YB_LibDefect_String_tostri(string, long long, "%lld", std::vsnprintf)
161 YB_LibDefect_String_tostri(string, unsigned long long, "%llu", std::vsnprintf)
162 # if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) && defined(_GLIBCXX_USE_WCHAR_T)
163 YB_LibDefect_String_tostri(wstring, int, L"%d", std::vswprintf)
164 YB_LibDefect_String_tostri(wstring, unsigned, L"%u", std::vswprintf)
165 YB_LibDefect_String_tostri(wstring, long, L"%ld", std::vswprintf)
166 YB_LibDefect_String_tostri(wstring, unsigned long, L"%lu", std::vswprintf)
167 YB_LibDefect_String_tostri(wstring, long long, L"%lld", std::vswprintf)
168 YB_LibDefect_String_tostri(wstring, unsigned long long, L"%llu", std::vswprintf)
169 # endif
170
171 # undef YB_LibDefect_String_tostri
172
173
174 # define YB_LibDefect_String_tostrf(_s, _t, _fmt, _cfname) \
175 inline _s \
176 to_##_s(_t __val) \
177 { \
178 return __gnu_cxx::__to_xstring<_s>(&_cfname, \
179 __gnu_cxx::__numeric_traits<_t>::__max_exponent10 + 20, \
180 _fmt, double(__val)); \
181 }
182
183 YB_LibDefect_String_tostrf(string, float, "%f", std::vsnprintf)
184 YB_LibDefect_String_tostrf(string, double, "%f", std::vsnprintf)
185 YB_LibDefect_String_tostrf(string, long double, "%f", std::vsnprintf)
186 # if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) && defined(_GLIBCXX_USE_WCHAR_T)
187 YB_LibDefect_String_tostrf(wstring, float, L"%f", std::vswprintf)
188 YB_LibDefect_String_tostrf(wstring, double, L"%f", std::vswprintf)
189 YB_LibDefect_String_tostrf(wstring, long double, L"%f", std::vswprintf)
190 # endif
191
192 # undef YB_LibDefect_String_tostrf
193
194 _GLIBCXX_END_NAMESPACE_VERSION
195
196 } // namespace std;
197
198 #endif /* ... __GXX_EXPERIMENTAL_CXX0X__ ... */
199
200 #endif
201
platform::KeyCodes::DS::L
Definition: Keys.h:227
std
Definition: memory.hpp:1100
platform::containers::wstring
basic_string< wchar_t > wstring
Definition: Container.h:108
cstdio.h
YSLib::IO::int
YF_API int
Definition: File.h:49
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430