YSTest: string.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
string.h
浏览该文件的文档.
1 /*
2 © 2012-2014 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
38 // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015 .
39 // NOTE: Fixed @ 4.8 for MinGW-W64.
40
41 #if defined(__GLIBCXX__) \
42 && (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L) \
43 && !(defined(_GLIBCXX_USE_C99) && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
44
45 #include <ext/string_conversions.h>
46
47 namespace std _GLIBCXX_VISIBILITY(default)
48 {
49
50 #ifndef _GLIBCXX_USE_C99
51
52 # ifndef __BIONIC__
53 extern "C" long long int
54 (strtoll)(const char* __restrict, char** __restrict, int) throw();
55 extern "C" unsigned long long int
56 (strtoull)(const char* __restrict, char** __restrict, int) throw();
57 using ::strtold;
58 extern "C" int
59 (vsnprintf)(char* __restrict, std::size_t, const char* __restrict,
60 __gnuc_va_list) throw();
61 # else
62 using ::vsnprintf;
64 # endif
65
66 using ::strtof;
67 using ::wcstol;
68 using ::wcstoul;
69 using ::wcstod;
70 # ifndef __BIONIC__
71 using ::wcstoll;
72 using ::wcstoull;
73 using ::wcstof;
74 using ::wcstold;
75 # endif
76
77 #endif
78
79
80 _GLIBCXX_BEGIN_NAMESPACE_VERSION
81
82 // 21.4 Numeric Conversions [string.conversions].
83
84 #define YB_LIBDEFECT_STOI(_s, _n, _t, _cfname) \
85 inline _t \
86 _n(const _s& __str, size_t* __idx = {}, int __base = 10) \
87 { \
88 return __gnu_cxx::__stoa(&_cfname, #_n, __str.c_str(), __idx, __base); \
89 }
90
91 inline int
92 stoi(const string& __str, size_t* __idx = {}, int __base = 10)
93 {
94 return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
95 __idx, __base);
96 }
97 YB_LIBDEFECT_STOI(string, stol, long, std::strtol)
98 YB_LIBDEFECT_STOI(string, stoul, unsigned long, std::strtoul)
99 #ifndef __BIONIC__
100 YB_LIBDEFECT_STOI(string, stoll, long long, std::strtoll)
101 YB_LIBDEFECT_STOI(string, stoull, unsigned long long, std::strtoull)
102 #endif
103 #ifdef _GLIBCXX_USE_WCHAR_T
104 inline int
105 stoi(const wstring& __str, size_t* __idx = {}, int __base = 10)
106 {
107 return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
108 __idx, __base);
109 }
110 YB_LIBDEFECT_STOI(wstring, stol, long, std::wcstol)
111 YB_LIBDEFECT_STOI(wstring, stoul, unsigned long, std::wcstoul)
112 # ifndef __BIONIC__
113 YB_LIBDEFECT_STOI(wstring, stoll, long long, std::wcstoll)
114 YB_LIBDEFECT_STOI(wstring, stoull, unsigned long long, std::wcstoull)
115 # endif
116 #endif
117
118 #undef YB_LIBDEFECT_STOI
119
120
121 #define YB_LIBDEFECT_STOF(_s, _n, _t, _cfname) \
122 inline _t \
123 _n(const _s& __str, size_t* __idx = {}) \
124 { \
125 return __gnu_cxx::__stoa(&_cfname, #_n, __str.c_str(), __idx); \
126 }
127
128 # ifndef __BIONIC__
129 // NOTE: Seems to be a bug of Clang++ 3.4.
130 // NOTE: strtof vs strtod.
131 YB_LIBDEFECT_STOF(string, stof, float, std::strtof)
132 YB_LIBDEFECT_STOF(string, stod, double, std::strtod)
133 YB_LIBDEFECT_STOF(string, stold, long double, std::strtold)
134 #ifdef _GLIBCXX_USE_WCHAR_T
135 // NOTE: wcstof vs wcstod.
136 YB_LIBDEFECT_STOF(wstring, stof, float, std::wcstof)
137 YB_LIBDEFECT_STOF(wstring, stod, double, std::wcstod)
138 YB_LIBDEFECT_STOF(wstring, stold, long double, std::wcstold)
139 #endif
140 # endif
141
142 #undef YB_LIBDEFECT_STOF
143
144
145 // NOTE: (v)snprintf vs sprintf.
146 #define YB_LIBDEFECT_TOSTRI(_s, _t, _fmt, _cfname) \
147 inline _s \
148 to_##_s(_t __val) \
149 { \
150 return __gnu_cxx::__to_xstring<_s>(&_cfname, \
151 sizeof(_t) * 4, _fmt, __val); \
152 }
153
154 // DR 1261.
155 YB_LIBDEFECT_TOSTRI(string, int, "%d", std::vsnprintf)
156 YB_LIBDEFECT_TOSTRI(string, unsigned, "%u", std::vsnprintf)
157 YB_LIBDEFECT_TOSTRI(string, long, "%ld", std::vsnprintf)
158 YB_LIBDEFECT_TOSTRI(string, unsigned long, "%lu", std::vsnprintf)
159 YB_LIBDEFECT_TOSTRI(string, long long, "%lld", std::vsnprintf)
160 YB_LIBDEFECT_TOSTRI(string, unsigned long long, "%llu", std::vsnprintf)
161 #if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) && defined(_GLIBCXX_USE_WCHAR_T)
162 YB_LIBDEFECT_TOSTRI(wstring, int, L"%d", std::vswprintf)
163 YB_LIBDEFECT_TOSTRI(wstring, unsigned, L"%u", std::vswprintf)
164 YB_LIBDEFECT_TOSTRI(wstring, long, L"%ld", std::vswprintf)
165 YB_LIBDEFECT_TOSTRI(wstring, unsigned long, L"%lu", std::vswprintf)
166 YB_LIBDEFECT_TOSTRI(wstring, long long, L"%lld", std::vswprintf)
167 YB_LIBDEFECT_TOSTRI(wstring, unsigned long long, L"%llu", std::vswprintf)
168 #endif
169
170 #undef YB_LIBDEFECT_TOSTRI
171
172
173 #define YB_LIBDEFECT_TOSTRF(_s, _t, _fmt, _cfname) \
174 inline _s \
175 to_##_s(_t __val) \
176 { \
177 return __gnu_cxx::__to_xstring<_s>(&_cfname, \
178 __gnu_cxx::__numeric_traits<_t>::__max_exponent10 + 20, \
179 _fmt, __val); \
180 }
181
182 YB_LIBDEFECT_TOSTRF(string, float, "%f", std::vsnprintf)
183 YB_LIBDEFECT_TOSTRF(string, double, "%f", std::vsnprintf)
184 YB_LIBDEFECT_TOSTRF(string, long double, "%f", std::vsnprintf)
185 #if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF) && defined(_GLIBCXX_USE_WCHAR_T)
186 YB_LIBDEFECT_TOSTRF(wstring, float, L"%f", std::vswprintf)
187 YB_LIBDEFECT_TOSTRF(wstring, double, L"%f", std::vswprintf)
188 YB_LIBDEFECT_TOSTRF(wstring, long double, L"%f", std::vswprintf)
189 #endif
190
191 #undef YB_LIBDEFECT_TOSTRF
192
193 _GLIBCXX_END_NAMESPACE_VERSION
194
195 } // namespace std;
196
197 #endif /* ... __GXX_EXPERIMENTAL_CXX0X__ ... */
198
199 #endif
200
YSLib::Drawing::size_t
size_t
Definition: ygdi.h:352
YSLib::UI::f
_tWidget _fCallable && f
Definition: ywgtevt.h:597