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