Coverage Report

Created: 2022-01-25 06:29

/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 "string"
10
#include "charconv"
11
#include "cstdlib"
12
#include "cerrno"
13
#include "limits"
14
#include "stdexcept"
15
#include <stdio.h>
16
#include "__debug"
17
18
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
19
#   include "cwchar"
20
#endif
21
22
_LIBCPP_BEGIN_NAMESPACE_STD
23
24
#ifndef _LIBCPP_ABI_NO_BASIC_STRING_BASE_CLASS
25
0
void __basic_string_common<true>::__throw_length_error() const {
26
0
    _VSTD::__throw_length_error("basic_string");
27
0
}
28
29
0
void __basic_string_common<true>::__throw_out_of_range() const {
30
0
    _VSTD::__throw_out_of_range("basic_string");
31
0
}
32
#endif
33
34
#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
35
#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
36
    _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
37
#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
38
        _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
39
#   endif
40
#else
41
    _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
42
#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
43
        _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
44
#   endif
45
#endif
46
#undef _LIBCPP_EXTERN_TEMPLATE_DEFINE
47
48
template string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
49
50
namespace
51
{
52
53
template<typename T>
54
inline
55
void throw_helper( const string& msg )
56
0
{
57
0
#ifndef _LIBCPP_NO_EXCEPTIONS
58
0
    throw T( msg );
59
#else
60
    fprintf(stderr, "%s\n", msg.c_str());
61
    _VSTD::abort();
62
#endif
63
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&)
64
65
inline
66
void throw_from_string_out_of_range( const string& func )
67
0
{
68
0
    throw_helper<out_of_range>(func + ": out of range");
69
0
}
70
71
inline
72
void throw_from_string_invalid_arg( const string& func )
73
0
{
74
0
    throw_helper<invalid_argument>(func + ": no conversion");
75
0
}
76
77
// as_integer
78
79
template<typename V, typename S, typename F>
80
inline
81
V
82
as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
83
0
{
84
0
    typename S::value_type* ptr = nullptr;
85
0
    const typename S::value_type* const p = str.c_str();
86
0
    typename remove_reference<decltype(errno)>::type errno_save = errno;
87
0
    errno = 0;
88
0
    V r = f(p, &ptr, base);
89
0
    swap(errno, errno_save);
90
0
    if (errno_save == ERANGE)
91
0
        throw_from_string_out_of_range(func);
92
0
    if (ptr == p)
93
0
        throw_from_string_invalid_arg(func);
94
0
    if (idx)
95
0
        *idx = static_cast<size_t>(ptr - p);
96
0
    return r;
97
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: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<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: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<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: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<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: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))
98
99
template<typename V, typename S>
100
inline
101
V
102
as_integer(const string& func, const S& s, size_t* idx, int base);
103
104
// string
105
template<>
106
inline
107
int
108
as_integer(const string& func, const string& s, size_t* idx, int base )
109
0
{
110
    // Use long as no Standard string to integer exists.
111
0
    long r = as_integer_helper<long>( func, s, idx, base, strtol );
112
0
    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
113
0
        throw_from_string_out_of_range(func);
114
0
    return static_cast<int>(r);
115
0
}
116
117
template<>
118
inline
119
long
120
as_integer(const string& func, const string& s, size_t* idx, int base )
121
0
{
122
0
    return as_integer_helper<long>( func, s, idx, base, strtol );
123
0
}
124
125
template<>
126
inline
127
unsigned long
128
as_integer( const string& func, const string& s, size_t* idx, int base )
129
0
{
130
0
    return as_integer_helper<unsigned long>( func, s, idx, base, strtoul );
131
0
}
132
133
template<>
134
inline
135
long long
136
as_integer( const string& func, const string& s, size_t* idx, int base )
137
0
{
138
0
    return as_integer_helper<long long>( func, s, idx, base, strtoll );
139
0
}
140
141
template<>
142
inline
143
unsigned long long
144
as_integer( const string& func, const string& s, size_t* idx, int base )
145
0
{
146
0
    return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
147
0
}
148
149
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
150
// wstring
151
template<>
152
inline
153
int
154
as_integer( const string& func, const wstring& s, size_t* idx, int base )
155
0
{
156
    // Use long as no Stantard string to integer exists.
157
0
    long r = as_integer_helper<long>( func, s, idx, base, wcstol );
158
0
    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
159
0
        throw_from_string_out_of_range(func);
160
0
    return static_cast<int>(r);
161
0
}
162
163
template<>
164
inline
165
long
166
as_integer( const string& func, const wstring& s, size_t* idx, int base )
167
0
{
168
0
    return as_integer_helper<long>( func, s, idx, base, wcstol );
169
0
}
170
171
template<>
172
inline
173
unsigned long
174
as_integer( const string& func, const wstring& s, size_t* idx, int base )
175
0
{
176
0
    return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul );
177
0
}
178
179
template<>
180
inline
181
long long
182
as_integer( const string& func, const wstring& s, size_t* idx, int base )
183
0
{
184
0
    return as_integer_helper<long long>( func, s, idx, base, wcstoll );
185
0
}
186
187
template<>
188
inline
189
unsigned long long
190
as_integer( const string& func, const wstring& s, size_t* idx, int base )
191
0
{
192
0
    return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
193
0
}
194
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
195
196
// as_float
197
198
template<typename V, typename S, typename F>
199
inline
200
V
201
as_float_helper(const string& func, const S& str, size_t* idx, F f )
202
0
{
203
0
    typename S::value_type* ptr = nullptr;
204
0
    const typename S::value_type* const p = str.c_str();
205
0
    typename remove_reference<decltype(errno)>::type errno_save = errno;
206
0
    errno = 0;
207
0
    V r = f(p, &ptr);
208
0
    swap(errno, errno_save);
209
0
    if (errno_save == ERANGE)
210
0
        throw_from_string_out_of_range(func);
211
0
    if (ptr == p)
212
0
        throw_from_string_invalid_arg(func);
213
0
    if (idx)
214
0
        *idx = static_cast<size_t>(ptr - p);
215
0
    return r;
216
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: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<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: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<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: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**))
217
218
template<typename V, typename S>
219
inline
220
V as_float( const string& func, const S& s, size_t* idx = nullptr );
221
222
template<>
223
inline
224
float
225
as_float( const string& func, const string& s, size_t* idx )
226
0
{
227
0
    return as_float_helper<float>( func, s, idx, strtof );
228
0
}
229
230
template<>
231
inline
232
double
233
as_float(const string& func, const string& s, size_t* idx )
234
0
{
235
0
    return as_float_helper<double>( func, s, idx, strtod );
236
0
}
237
238
template<>
239
inline
240
long double
241
as_float( const string& func, const string& s, size_t* idx )
242
0
{
243
0
    return as_float_helper<long double>( func, s, idx, strtold );
244
0
}
245
246
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
247
template<>
248
inline
249
float
250
as_float( const string& func, const wstring& s, size_t* idx )
251
0
{
252
0
    return as_float_helper<float>( func, s, idx, wcstof );
253
0
}
254
255
template<>
256
inline
257
double
258
as_float( const string& func, const wstring& s, size_t* idx )
259
0
{
260
0
    return as_float_helper<double>( func, s, idx, wcstod );
261
0
}
262
263
template<>
264
inline
265
long double
266
as_float( const string& func, const wstring& s, size_t* idx )
267
0
{
268
0
    return as_float_helper<long double>( func, s, idx, wcstold );
269
0
}
270
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
271
272
}  // unnamed namespace
273
274
int
275
stoi(const string& str, size_t* idx, int base)
276
0
{
277
0
    return as_integer<int>( "stoi", str, idx, base );
278
0
}
279
280
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
281
int
282
stoi(const wstring& str, size_t* idx, int base)
283
0
{
284
0
    return as_integer<int>( "stoi", str, idx, base );
285
0
}
286
#endif
287
288
long
289
stol(const string& str, size_t* idx, int base)
290
0
{
291
0
    return as_integer<long>( "stol", str, idx, base );
292
0
}
293
294
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
295
long
296
stol(const wstring& str, size_t* idx, int base)
297
0
{
298
0
    return as_integer<long>( "stol", str, idx, base );
299
0
}
300
#endif
301
302
unsigned long
303
stoul(const string& str, size_t* idx, int base)
304
0
{
305
0
    return as_integer<unsigned long>( "stoul", str, idx, base );
306
0
}
307
308
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
309
unsigned long
310
stoul(const wstring& str, size_t* idx, int base)
311
0
{
312
0
    return as_integer<unsigned long>( "stoul", str, idx, base );
313
0
}
314
#endif
315
316
long long
317
stoll(const string& str, size_t* idx, int base)
318
0
{
319
0
    return as_integer<long long>( "stoll", str, idx, base );
320
0
}
321
322
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
323
long long
324
stoll(const wstring& str, size_t* idx, int base)
325
0
{
326
0
    return as_integer<long long>( "stoll", str, idx, base );
327
0
}
328
#endif
329
330
unsigned long long
331
stoull(const string& str, size_t* idx, int base)
332
0
{
333
0
    return as_integer<unsigned long long>( "stoull", str, idx, base );
334
0
}
335
336
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
337
unsigned long long
338
stoull(const wstring& str, size_t* idx, int base)
339
0
{
340
0
    return as_integer<unsigned long long>( "stoull", str, idx, base );
341
0
}
342
#endif
343
344
float
345
stof(const string& str, size_t* idx)
346
0
{
347
0
    return as_float<float>( "stof", str, idx );
348
0
}
349
350
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
351
float
352
stof(const wstring& str, size_t* idx)
353
0
{
354
0
    return as_float<float>( "stof", str, idx );
355
0
}
356
#endif
357
358
double
359
stod(const string& str, size_t* idx)
360
0
{
361
0
    return as_float<double>( "stod", str, idx );
362
0
}
363
364
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
365
double
366
stod(const wstring& str, size_t* idx)
367
0
{
368
0
    return as_float<double>( "stod", str, idx );
369
0
}
370
#endif
371
372
long double
373
stold(const string& str, size_t* idx)
374
0
{
375
0
    return as_float<long double>( "stold", str, idx );
376
0
}
377
378
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
379
long double
380
stold(const wstring& str, size_t* idx)
381
0
{
382
0
    return as_float<long double>( "stold", str, idx );
383
0
}
384
#endif
385
386
// to_string
387
388
namespace
389
{
390
391
// as_string
392
393
template<typename S, typename P, typename V >
394
inline
395
S
396
as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a)
397
0
{
398
0
    typedef typename S::size_type size_type;
399
0
    size_type available = s.size();
400
0
    while (true)
401
0
    {
402
0
        int status = sprintf_like(&s[0], available + 1, fmt, a);
403
0
        if ( status >= 0 )
404
0
        {
405
0
            size_type used = static_cast<size_type>(status);
406
0
            if ( used <= available )
407
0
            {
408
0
                s.resize( used );
409
0
                break;
410
0
            }
411
0
            available = used; // Assume this is advice of how much space we need.
412
0
        }
413
0
        else
414
0
            available = available * 2 + 1;
415
0
        s.resize(available);
416
0
    }
417
0
    return s;
418
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)
419
420
template <class S>
421
struct initial_string;
422
423
template <>
424
struct initial_string<string>
425
{
426
    string
427
    operator()() const
428
0
    {
429
0
        string s;
430
0
        s.resize(s.capacity());
431
0
        return s;
432
0
    }
433
};
434
435
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
436
template <>
437
struct initial_string<wstring>
438
{
439
    wstring
440
    operator()() const
441
0
    {
442
0
        wstring s(20, wchar_t());
443
0
        s.resize(s.capacity());
444
0
        return s;
445
0
    }
446
};
447
448
typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...);
449
450
inline
451
wide_printf
452
get_swprintf()
453
0
{
454
0
#ifndef _LIBCPP_MSVCRT
455
0
    return swprintf;
456
#else
457
    return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
458
#endif
459
0
}
460
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
461
462
template <typename S, typename V>
463
S i_to_string(V v)
464
1.06M
{
465
//  numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
466
//  For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
467
//  so we need +1 here.
468
1.06M
    constexpr size_t bufsize = numeric_limits<V>::digits10 + 2;  // +1 for minus, +1 for digits10
469
1.06M
    char buf[bufsize];
470
1.06M
    const auto res = to_chars(buf, buf + bufsize, v);
471
1.06M
    _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value");
472
1.06M
    return S(buf, res.ptr);
473
1.06M
}
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
464
1.06M
{
465
//  numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
466
//  For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
467
//  so we need +1 here.
468
1.06M
    constexpr size_t bufsize = numeric_limits<V>::digits10 + 2;  // +1 for minus, +1 for digits10
469
1.06M
    char buf[bufsize];
470
1.06M
    const auto res = to_chars(buf, buf + bufsize, v);
471
1.06M
    _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value");
472
1.06M
    return S(buf, res.ptr);
473
1.06M
}
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
464
16
{
465
//  numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
466
//  For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
467
//  so we need +1 here.
468
16
    constexpr size_t bufsize = numeric_limits<V>::digits10 + 2;  // +1 for minus, +1 for digits10
469
16
    char buf[bufsize];
470
16
    const auto res = to_chars(buf, buf + bufsize, v);
471
16
    _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value");
472
16
    return S(buf, res.ptr);
473
16
}
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)
474
475
}  // unnamed namespace
476
477
0
string  to_string (int val)                { return i_to_string< string>(val); }
478
0
string  to_string (long val)               { return i_to_string< string>(val); }
479
0
string  to_string (long long val)          { return i_to_string< string>(val); }
480
1.06M
string  to_string (unsigned val)           { return i_to_string< string>(val); }
481
16
string  to_string (unsigned long val)      { return i_to_string< string>(val); }
482
0
string  to_string (unsigned long long val) { return i_to_string< string>(val); }
483
484
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
485
0
wstring to_wstring(int val)                { return i_to_string<wstring>(val); }
486
0
wstring to_wstring(long val)               { return i_to_string<wstring>(val); }
487
0
wstring to_wstring(long long val)          { return i_to_string<wstring>(val); }
488
0
wstring to_wstring(unsigned val)           { return i_to_string<wstring>(val); }
489
0
wstring to_wstring(unsigned long val)      { return i_to_string<wstring>(val); }
490
0
wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); }
491
#endif
492
493
0
string  to_string (float val)       { return as_string(snprintf,       initial_string< string>()(),   "%f", val); }
494
0
string  to_string (double val)      { return as_string(snprintf,       initial_string< string>()(),   "%f", val); }
495
0
string  to_string (long double val) { return as_string(snprintf,       initial_string< string>()(),  "%Lf", val); }
496
497
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
498
0
wstring to_wstring(float val)       { return as_string(get_swprintf(), initial_string<wstring>()(),  L"%f", val); }
499
0
wstring to_wstring(double val)      { return as_string(get_swprintf(), initial_string<wstring>()(),  L"%f", val); }
500
0
wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); }
501
#endif
502
503
_LIBCPP_END_NAMESPACE_STD