Coverage Report

Created: 2020-09-22 08:39

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