/Users/buildslave/jenkins/workspace/coverage/llvm-project/libcxx/src/string.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===----------------------------------------------------------------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include <__assert> |
10 | | #include <cerrno> |
11 | | #include <charconv> |
12 | | #include <cstdlib> |
13 | | #include <limits> |
14 | | #include <stdexcept> |
15 | | #include <stdio.h> |
16 | | #include <string> |
17 | | |
18 | | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
19 | | # include <cwchar> |
20 | | #endif |
21 | | |
22 | | _LIBCPP_BEGIN_NAMESPACE_STD |
23 | | |
24 | | #ifndef _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON |
25 | | |
26 | | template <bool> |
27 | | struct __basic_string_common; |
28 | | |
29 | | // The struct isn't declared anymore in the headers. It's only here for ABI compatibility. |
30 | | template <> |
31 | | struct __basic_string_common<true> { |
32 | | _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const; |
33 | | _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const; |
34 | | }; |
35 | | |
36 | 0 | void __basic_string_common<true>::__throw_length_error() const { |
37 | 0 | std::__throw_length_error("basic_string"); |
38 | 0 | } |
39 | 0 | void __basic_string_common<true>::__throw_out_of_range() const { |
40 | 0 | std::__throw_out_of_range("basic_string"); |
41 | 0 | } |
42 | | |
43 | | #endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON |
44 | | |
45 | | #define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__; |
46 | | #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
47 | | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char) |
48 | | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
49 | | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t) |
50 | | # endif |
51 | | #else |
52 | | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char) |
53 | | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
54 | | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t) |
55 | | # endif |
56 | | #endif |
57 | | #undef _LIBCPP_EXTERN_TEMPLATE_DEFINE |
58 | | |
59 | | template string operator+<char, char_traits<char>, allocator<char>>(char const*, string const&); |
60 | | |
61 | | namespace |
62 | | { |
63 | | |
64 | | template<typename T> |
65 | 0 | inline void throw_helper(const string& msg) { |
66 | 0 | #ifndef _LIBCPP_NO_EXCEPTIONS |
67 | 0 | throw T(msg); |
68 | | #else |
69 | | fprintf(stderr, "%s\n", msg.c_str()); |
70 | | _VSTD::abort(); |
71 | | #endif |
72 | 0 | } Unexecuted instantiation: string.cpp:void std::__1::(anonymous namespace)::throw_helper<std::invalid_argument>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: string.cpp:void std::__1::(anonymous namespace)::throw_helper<std::out_of_range>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
73 | | |
74 | 0 | inline void throw_from_string_out_of_range(const string& func) { |
75 | 0 | throw_helper<out_of_range>(func + ": out of range"); |
76 | 0 | } |
77 | | |
78 | 0 | inline void throw_from_string_invalid_arg(const string& func) { |
79 | 0 | throw_helper<invalid_argument>(func + ": no conversion"); |
80 | 0 | } |
81 | | |
82 | | // as_integer |
83 | | |
84 | | template<typename V, typename S, typename F> |
85 | 0 | inline V as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f) { |
86 | 0 | typename S::value_type* ptr = nullptr; |
87 | 0 | const typename S::value_type* const p = str.c_str(); |
88 | 0 | typename remove_reference<decltype(errno)>::type errno_save = errno; |
89 | 0 | errno = 0; |
90 | 0 | V r = f(p, &ptr, base); |
91 | 0 | swap(errno, errno_save); |
92 | 0 | if (errno_save == ERANGE) |
93 | 0 | throw_from_string_out_of_range(func); |
94 | 0 | if (ptr == p) |
95 | 0 | throw_from_string_invalid_arg(func); |
96 | 0 | if (idx) |
97 | 0 | *idx = static_cast<size_t>(ptr - p); |
98 | 0 | return r; |
99 | 0 | } Unexecuted instantiation: string.cpp:long std::__1::(anonymous namespace)::as_integer_helper<long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long (*)(char const*, char**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long*, int, long (*)(char const*, char**, int)) Unexecuted instantiation: string.cpp:unsigned long std::__1::(anonymous namespace)::as_integer_helper<unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long (*)(char const*, char**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long*, int, unsigned long (*)(char const*, char**, int)) Unexecuted instantiation: string.cpp:long long std::__1::(anonymous namespace)::as_integer_helper<long long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long long (*)(char const*, char**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long*, int, long long (*)(char const*, char**, int)) Unexecuted instantiation: string.cpp:unsigned long long std::__1::(anonymous namespace)::as_integer_helper<unsigned long long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long long (*)(char const*, char**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long*, int, unsigned long long (*)(char const*, char**, int)) Unexecuted instantiation: string.cpp:long std::__1::(anonymous namespace)::as_integer_helper<long, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, long (*)(wchar_t const*, wchar_t**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, unsigned long*, int, long (*)(wchar_t const*, wchar_t**, int)) Unexecuted instantiation: string.cpp:unsigned long std::__1::(anonymous namespace)::as_integer_helper<unsigned long, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, unsigned long (*)(wchar_t const*, wchar_t**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, unsigned long*, int, unsigned long (*)(wchar_t const*, wchar_t**, int)) Unexecuted instantiation: string.cpp:long long std::__1::(anonymous namespace)::as_integer_helper<long long, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, long long (*)(wchar_t const*, wchar_t**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, unsigned long*, int, long long (*)(wchar_t const*, wchar_t**, int)) Unexecuted instantiation: string.cpp:unsigned long long std::__1::(anonymous namespace)::as_integer_helper<unsigned long long, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, unsigned long long (*)(wchar_t const*, wchar_t**, int)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, unsigned long*, int, unsigned long long (*)(wchar_t const*, wchar_t**, int)) |
100 | | |
101 | | template<typename V, typename S> |
102 | | inline V as_integer(const string& func, const S& s, size_t* idx, int base); |
103 | | |
104 | | // string |
105 | | template<> |
106 | 0 | inline int as_integer(const string& func, const string& s, size_t* idx, int base) { |
107 | | // Use long as no Standard string to integer exists. |
108 | 0 | long r = as_integer_helper<long>(func, s, idx, base, strtol); |
109 | 0 | if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) |
110 | 0 | throw_from_string_out_of_range(func); |
111 | 0 | return static_cast<int>(r); |
112 | 0 | } |
113 | | |
114 | | template<> |
115 | 0 | inline long as_integer(const string& func, const string& s, size_t* idx, int base) { |
116 | 0 | return as_integer_helper<long>(func, s, idx, base, strtol); |
117 | 0 | } |
118 | | |
119 | | template<> |
120 | 0 | inline unsigned long as_integer(const string& func, const string& s, size_t* idx, int base) { |
121 | 0 | return as_integer_helper<unsigned long>(func, s, idx, base, strtoul); |
122 | 0 | } |
123 | | |
124 | | template<> |
125 | 0 | inline long long as_integer(const string& func, const string& s, size_t* idx, int base) { |
126 | 0 | return as_integer_helper<long long>(func, s, idx, base, strtoll); |
127 | 0 | } |
128 | | |
129 | | template<> |
130 | 0 | inline unsigned long long as_integer(const string& func, const string& s, size_t* idx, int base) { |
131 | 0 | return as_integer_helper<unsigned long long>(func, s, idx, base, strtoull); |
132 | 0 | } |
133 | | |
134 | | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
135 | | // wstring |
136 | | template<> |
137 | 0 | inline int as_integer(const string& func, const wstring& s, size_t* idx, int base) { |
138 | | // Use long as no Stantard string to integer exists. |
139 | 0 | long r = as_integer_helper<long>(func, s, idx, base, wcstol); |
140 | 0 | if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r) |
141 | 0 | throw_from_string_out_of_range(func); |
142 | 0 | return static_cast<int>(r); |
143 | 0 | } |
144 | | |
145 | | template<> |
146 | 0 | inline long as_integer(const string& func, const wstring& s, size_t* idx, int base) { |
147 | 0 | return as_integer_helper<long>(func, s, idx, base, wcstol); |
148 | 0 | } |
149 | | |
150 | | template<> |
151 | | inline |
152 | | unsigned long |
153 | | as_integer(const string& func, const wstring& s, size_t* idx, int base) |
154 | 0 | { |
155 | 0 | return as_integer_helper<unsigned long>(func, s, idx, base, wcstoul); |
156 | 0 | } |
157 | | |
158 | | template<> |
159 | 0 | inline long long as_integer(const string& func, const wstring& s, size_t* idx, int base) { |
160 | 0 | return as_integer_helper<long long>(func, s, idx, base, wcstoll); |
161 | 0 | } |
162 | | |
163 | | template<> |
164 | 0 | inline unsigned long long as_integer(const string& func, const wstring& s, size_t* idx, int base) { |
165 | 0 | return as_integer_helper<unsigned long long>(func, s, idx, base, wcstoull); |
166 | 0 | } |
167 | | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
168 | | |
169 | | // as_float |
170 | | |
171 | | template<typename V, typename S, typename F> |
172 | 0 | inline V as_float_helper(const string& func, const S& str, size_t* idx, F f) { |
173 | 0 | typename S::value_type* ptr = nullptr; |
174 | 0 | const typename S::value_type* const p = str.c_str(); |
175 | 0 | typename remove_reference<decltype(errno)>::type errno_save = errno; |
176 | 0 | errno = 0; |
177 | 0 | V r = f(p, &ptr); |
178 | 0 | swap(errno, errno_save); |
179 | 0 | if (errno_save == ERANGE) |
180 | 0 | throw_from_string_out_of_range(func); |
181 | 0 | if (ptr == p) |
182 | 0 | throw_from_string_invalid_arg(func); |
183 | 0 | if (idx) |
184 | 0 | *idx = static_cast<size_t>(ptr - p); |
185 | 0 | return r; |
186 | 0 | } Unexecuted instantiation: string.cpp:float std::__1::(anonymous namespace)::as_float_helper<float, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float (*)(char const*, char**)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long*, float (*)(char const*, char**)) Unexecuted instantiation: string.cpp:double std::__1::(anonymous namespace)::as_float_helper<double, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, double (*)(char const*, char**)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long*, double (*)(char const*, char**)) Unexecuted instantiation: string.cpp:long double std::__1::(anonymous namespace)::as_float_helper<long double, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long double (*)(char const*, char**)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long*, long double (*)(char const*, char**)) Unexecuted instantiation: string.cpp:float std::__1::(anonymous namespace)::as_float_helper<float, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, float (*)(wchar_t const*, wchar_t**)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, unsigned long*, float (*)(wchar_t const*, wchar_t**)) Unexecuted instantiation: string.cpp:double std::__1::(anonymous namespace)::as_float_helper<double, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, double (*)(wchar_t const*, wchar_t**)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, unsigned long*, double (*)(wchar_t const*, wchar_t**)) Unexecuted instantiation: string.cpp:long double std::__1::(anonymous namespace)::as_float_helper<long double, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, long double (*)(wchar_t const*, wchar_t**)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, unsigned long*, long double (*)(wchar_t const*, wchar_t**)) |
187 | | |
188 | | template<typename V, typename S> |
189 | | inline V as_float(const string& func, const S& s, size_t* idx = nullptr); |
190 | | |
191 | | template<> |
192 | 0 | inline float as_float(const string& func, const string& s, size_t* idx) { |
193 | 0 | return as_float_helper<float>(func, s, idx, strtof); |
194 | 0 | } |
195 | | |
196 | | template<> |
197 | 0 | inline double as_float(const string& func, const string& s, size_t* idx) { |
198 | 0 | return as_float_helper<double>(func, s, idx, strtod); |
199 | 0 | } |
200 | | |
201 | | template<> |
202 | 0 | inline long double as_float(const string& func, const string& s, size_t* idx) { |
203 | 0 | return as_float_helper<long double>(func, s, idx, strtold); |
204 | 0 | } |
205 | | |
206 | | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
207 | | template<> |
208 | 0 | inline float as_float(const string& func, const wstring& s, size_t* idx) { |
209 | 0 | return as_float_helper<float>(func, s, idx, wcstof); |
210 | 0 | } |
211 | | |
212 | | template<> |
213 | 0 | inline double as_float(const string& func, const wstring& s, size_t* idx) { |
214 | 0 | return as_float_helper<double>(func, s, idx, wcstod); |
215 | 0 | } |
216 | | |
217 | | template<> |
218 | 0 | inline long double as_float(const string& func, const wstring& s, size_t* idx) { |
219 | 0 | return as_float_helper<long double>(func, s, idx, wcstold); |
220 | 0 | } |
221 | | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
222 | | |
223 | | } // unnamed namespace |
224 | | |
225 | 0 | int stoi(const string& str, size_t* idx, int base) { |
226 | 0 | return as_integer<int>("stoi", str, idx, base); |
227 | 0 | } |
228 | | |
229 | 0 | long stol(const string& str, size_t* idx, int base) { |
230 | 0 | return as_integer<long>("stol", str, idx, base); |
231 | 0 | } |
232 | | |
233 | 0 | unsigned long stoul(const string& str, size_t* idx, int base) { |
234 | 0 | return as_integer<unsigned long>("stoul", str, idx, base); |
235 | 0 | } |
236 | | |
237 | 0 | long long stoll(const string& str, size_t* idx, int base) { |
238 | 0 | return as_integer<long long>("stoll", str, idx, base); |
239 | 0 | } |
240 | | |
241 | 0 | unsigned long long stoull(const string& str, size_t* idx, int base) { |
242 | 0 | return as_integer<unsigned long long>("stoull", str, idx, base); |
243 | 0 | } |
244 | | |
245 | 0 | float stof(const string& str, size_t* idx) { |
246 | 0 | return as_float<float>("stof", str, idx); |
247 | 0 | } |
248 | | |
249 | 0 | double stod(const string& str, size_t* idx) { |
250 | 0 | return as_float<double>("stod", str, idx); |
251 | 0 | } |
252 | | |
253 | 0 | long double stold(const string& str, size_t* idx) { |
254 | 0 | return as_float<long double>("stold", str, idx); |
255 | 0 | } |
256 | | |
257 | | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
258 | 0 | int stoi(const wstring& str, size_t* idx, int base) { |
259 | 0 | return as_integer<int>("stoi", str, idx, base); |
260 | 0 | } |
261 | | |
262 | 0 | long stol(const wstring& str, size_t* idx, int base) { |
263 | 0 | return as_integer<long>("stol", str, idx, base); |
264 | 0 | } |
265 | | |
266 | 0 | unsigned long stoul(const wstring& str, size_t* idx, int base) { |
267 | 0 | return as_integer<unsigned long>("stoul", str, idx, base); |
268 | 0 | } |
269 | | |
270 | 0 | long long stoll(const wstring& str, size_t* idx, int base) { |
271 | 0 | return as_integer<long long>("stoll", str, idx, base); |
272 | 0 | } |
273 | | |
274 | 0 | unsigned long long stoull(const wstring& str, size_t* idx, int base) { |
275 | 0 | return as_integer<unsigned long long>("stoull", str, idx, base); |
276 | 0 | } |
277 | | |
278 | 0 | float stof(const wstring& str, size_t* idx) { |
279 | 0 | return as_float<float>("stof", str, idx); |
280 | 0 | } |
281 | | |
282 | 0 | double stod(const wstring& str, size_t* idx) { |
283 | 0 | return as_float<double>("stod", str, idx); |
284 | 0 | } |
285 | | |
286 | 0 | long double stold(const wstring& str, size_t* idx) { |
287 | 0 | return as_float<long double>("stold", str, idx); |
288 | 0 | } |
289 | | #endif // !_LIBCPP_HAS_NO_WIDE_CHARACTERS |
290 | | |
291 | | // to_string |
292 | | |
293 | | namespace |
294 | | { |
295 | | |
296 | | // as_string |
297 | | |
298 | | template<typename S, typename P, typename V > |
299 | 0 | inline S as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) { |
300 | 0 | typedef typename S::size_type size_type; |
301 | 0 | size_type available = s.size(); |
302 | 0 | while (true) { |
303 | 0 | int status = sprintf_like(&s[0], available + 1, fmt, a); |
304 | 0 | if (status >= 0) { |
305 | 0 | size_type used = static_cast<size_type>(status); |
306 | 0 | if (used <= available) { |
307 | 0 | s.resize(used); |
308 | 0 | break; |
309 | 0 | } |
310 | 0 | available = used; // Assume this is advice of how much space we need. |
311 | 0 | } |
312 | 0 | else |
313 | 0 | available = available * 2 + 1; |
314 | 0 | s.resize(available); |
315 | 0 | } |
316 | 0 | return s; |
317 | 0 | } Unexecuted instantiation: string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::as_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int (*)(char*, unsigned long, char const*, ...), float>(int (*)(char*, unsigned long, char const*, ...), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::value_type const*, float) Unexecuted instantiation: string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::as_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int (*)(char*, unsigned long, char const*, ...), double>(int (*)(char*, unsigned long, char const*, ...), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::value_type const*, double) Unexecuted instantiation: string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::as_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int (*)(char*, unsigned long, char const*, ...), long double>(int (*)(char*, unsigned long, char const*, ...), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::value_type const*, long double) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::as_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, int (*)(wchar_t*, unsigned long, wchar_t const*, ...), float>(int (*)(wchar_t*, unsigned long, wchar_t const*, ...), std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >::value_type const*, float) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::as_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, int (*)(wchar_t*, unsigned long, wchar_t const*, ...), double>(int (*)(wchar_t*, unsigned long, wchar_t const*, ...), std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >::value_type const*, double) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::as_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, int (*)(wchar_t*, unsigned long, wchar_t const*, ...), long double>(int (*)(wchar_t*, unsigned long, wchar_t const*, ...), std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >::value_type const*, long double) |
318 | | |
319 | | template <class S> |
320 | | struct initial_string; |
321 | | |
322 | | template <> |
323 | | struct initial_string<string> { |
324 | 0 | string operator()() const { |
325 | 0 | string s; |
326 | 0 | s.resize(s.capacity()); |
327 | 0 | return s; |
328 | 0 | } |
329 | | }; |
330 | | |
331 | | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
332 | | template <> |
333 | | struct initial_string<wstring> { |
334 | 0 | wstring operator()() const { |
335 | 0 | wstring s(20, wchar_t()); |
336 | 0 | s.resize(s.capacity()); |
337 | 0 | return s; |
338 | 0 | } |
339 | | }; |
340 | | |
341 | | typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...); |
342 | | |
343 | 0 | inline wide_printf get_swprintf() { |
344 | 0 | #ifndef _LIBCPP_MSVCRT |
345 | 0 | return swprintf; |
346 | | #else |
347 | | return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf); |
348 | | #endif |
349 | 0 | } |
350 | | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
351 | | |
352 | | template <typename S, typename V> |
353 | 1.42M | S i_to_string(V v) { |
354 | | // numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers. |
355 | | // For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented), |
356 | | // so we need +1 here. |
357 | 1.42M | constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10 |
358 | 1.42M | char buf[bufsize]; |
359 | 1.42M | const auto res = to_chars(buf, buf + bufsize, v); |
360 | 1.42M | _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value"); |
361 | 1.42M | return S(buf, res.ptr); |
362 | 1.42M | } Unexecuted instantiation: string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>(int) Unexecuted instantiation: string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long>(long) Unexecuted instantiation: string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long long>(long long) string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned int>(unsigned int) Line | Count | Source | 353 | 1.42M | S i_to_string(V v) { | 354 | | // numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers. | 355 | | // For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented), | 356 | | // so we need +1 here. | 357 | 1.42M | constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10 | 358 | 1.42M | char buf[bufsize]; | 359 | 1.42M | const auto res = to_chars(buf, buf + bufsize, v); | 360 | 1.42M | _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value"); | 361 | 1.42M | return S(buf, res.ptr); | 362 | 1.42M | } |
string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long>(unsigned long) Line | Count | Source | 353 | 22 | S i_to_string(V v) { | 354 | | // numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers. | 355 | | // For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented), | 356 | | // so we need +1 here. | 357 | 22 | constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10 | 358 | 22 | char buf[bufsize]; | 359 | 22 | const auto res = to_chars(buf, buf + bufsize, v); | 360 | 22 | _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value"); | 361 | 22 | return S(buf, res.ptr); | 362 | 22 | } |
Unexecuted instantiation: string.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned long long>(unsigned long long) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, int>(int) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, long>(long) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, long long>(long long) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, unsigned int>(unsigned int) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, unsigned long>(unsigned long) Unexecuted instantiation: string.cpp:std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > std::__1::(anonymous namespace)::i_to_string<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, unsigned long long>(unsigned long long) |
363 | | |
364 | | } // unnamed namespace |
365 | | |
366 | 0 | string to_string (int val) { return i_to_string< string>(val); } |
367 | 0 | string to_string (long val) { return i_to_string< string>(val); } |
368 | 0 | string to_string (long long val) { return i_to_string< string>(val); } |
369 | 1.42M | string to_string (unsigned val) { return i_to_string< string>(val); } |
370 | 22 | string to_string (unsigned long val) { return i_to_string< string>(val); } |
371 | 0 | string to_string (unsigned long long val) { return i_to_string< string>(val); } |
372 | | |
373 | | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
374 | 0 | wstring to_wstring(int val) { return i_to_string<wstring>(val); } |
375 | 0 | wstring to_wstring(long val) { return i_to_string<wstring>(val); } |
376 | 0 | wstring to_wstring(long long val) { return i_to_string<wstring>(val); } |
377 | 0 | wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); } |
378 | 0 | wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); } |
379 | 0 | wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); } |
380 | | #endif |
381 | | |
382 | 0 | string to_string (float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); } |
383 | 0 | string to_string (double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); } |
384 | 0 | string to_string (long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); } |
385 | | |
386 | | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
387 | 0 | wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); } |
388 | 0 | wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); } |
389 | 0 | wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); } |
390 | | #endif |
391 | | |
392 | | _LIBCPP_END_NAMESPACE_STD |