| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#ifndef _STRING_CONVERSIONS_H |
| 30 |
#define _STRING_CONVERSIONS_H 1 |
| 31 |
|
| 32 |
#ifdef _GLIBCXX_SYSHDR |
| 33 |
#pragma GCC system_header |
| 34 |
#endif |
| 35 |
|
| 36 |
#include <bits/requires_hosted.h> |
| 37 |
|
| 38 |
#if __cplusplus < 201103L |
| 39 |
# include <bits/c++0x_warning.h> |
| 40 |
#else |
| 41 |
|
| 42 |
#include <bits/c++config.h> |
| 43 |
#include <ext/numeric_traits.h> |
| 44 |
#include <bits/functexcept.h> |
| 45 |
#include <cstdlib> |
| 46 |
#include <cwchar> |
| 47 |
#include <cstdio> |
| 48 |
#include <cerrno> |
| 49 |
|
| 50 |
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) |
| 51 |
{ |
| 52 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 53 |
|
| 54 |
|
| 55 |
template<typename _TRet, typename _Ret = _TRet, typename _CharT, |
| 56 |
typename... _Base> |
| 57 |
_Ret |
| 58 |
__stoa(_TRet (*__convf) (const _CharT*, _CharT**, _Base...), |
| 59 |
const char* __name, const _CharT* __str, std::size_t* __idx, |
| 60 |
_Base... __base) |
| 61 |
{ |
| 62 |
_Ret __ret; |
| 63 |
|
| 64 |
_CharT* __endptr; |
| 65 |
|
| 66 |
struct _Save_errno { |
| 67 |
_Save_errno() : _M_errno(errno) { errno = 0; } |
| 68 |
~_Save_errno() { if (errno == 0) errno = _M_errno; } |
| 69 |
int _M_errno; |
| 70 |
} const __save_errno; |
| 71 |
|
| 72 |
struct _Range_chk { |
| 73 |
static bool |
| 74 |
_S_chk(_TRet, std::false_type) { return false; } |
| 75 |
|
| 76 |
static bool |
| 77 |
_S_chk(_TRet __val, std::true_type) |
| 78 |
{ |
| 79 |
return __val < _TRet(__numeric_traits<int>::__min) |
| 80 |
|| __val > _TRet(__numeric_traits<int>::__max); |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
const _TRet __tmp = __convf(__str, &__endptr, __base...); |
| 85 |
|
| 86 |
if (__endptr == __str) |
| 87 |
std::__throw_invalid_argument(__name); |
| 88 |
else if (errno == ERANGE |
| 89 |
|| _Range_chk::_S_chk(__tmp, std::is_same<_Ret, int>{})) |
| 90 |
std::__throw_out_of_range(__name); |
| 91 |
else |
| 92 |
__ret = __tmp; |
| 93 |
|
| 94 |
if (__idx) |
| 95 |
*__idx = __endptr - __str; |
| 96 |
|
| 97 |
return __ret; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
template<typename _String, typename _CharT = typename _String::value_type> |
| 102 |
_String |
| 103 |
__to_xstring(int (*__convf) (_CharT*, std::size_t, const _CharT*, |
| 104 |
__builtin_va_list), std::size_t __n, |
| 105 |
const _CharT* __fmt, ...) |
| 106 |
{ |
| 107 |
|
| 108 |
|
| 109 |
_CharT* __s = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
| 110 |
* __n)); |
| 111 |
|
| 112 |
__builtin_va_list __args; |
| 113 |
__builtin_va_start(__args, __fmt); |
| 114 |
|
| 115 |
const int __len = __convf(__s, __n, __fmt, __args); |
| 116 |
|
| 117 |
__builtin_va_end(__args); |
| 118 |
|
| 119 |
return _String(__s, __s + __len); |
| 120 |
} |
| 121 |
|
| 122 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 123 |
} |
| 124 |
|
| 125 |
#endif |
| 126 |
|
| 127 |
#endif |