Coverage Report

Created: 2020-02-15 09:57

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