Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _STRING_CONVERSIONS_H
00030 #define _STRING_CONVERSIONS_H 1
00031
00032 #pragma GCC system_header
00033
00034 #include <bits/c++config.h>
00035 #include <ext/numeric_traits.h>
00036 #include <bits/functexcept.h>
00037 #include <cstdlib>
00038 #include <cwchar>
00039 #include <cstdio>
00040 #include <cerrno>
00041
00042 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
00043 {
00044 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00045
00046
00047 template<typename _TRet, typename _Ret = _TRet, typename _CharT,
00048 typename... _Base>
00049 _Ret
00050 __stoa(_TRet (*__convf) (const _CharT*, _CharT**, _Base...),
00051 const char* __name, const _CharT* __str, std::size_t* __idx,
00052 _Base... __base)
00053 {
00054 _Ret __ret;
00055
00056 _CharT* __endptr;
00057 errno = 0;
00058 const _TRet __tmp = __convf(__str, &__endptr, __base...);
00059
00060 if (__endptr == __str)
00061 std::__throw_invalid_argument(__name);
00062 else if (errno == ERANGE
00063 || (std::__are_same<_Ret, int>::__value
00064 && (__tmp < __numeric_traits<int>::__min
00065 || __tmp > __numeric_traits<int>::__max)))
00066 std::__throw_out_of_range(__name);
00067 else
00068 __ret = __tmp;
00069
00070 if (__idx)
00071 *__idx = __endptr - __str;
00072
00073 return __ret;
00074 }
00075
00076
00077 template<typename _String, typename _CharT = typename _String::value_type>
00078 _String
00079 __to_xstring(int (*__convf) (_CharT*, std::size_t, const _CharT*,
00080 __builtin_va_list), std::size_t __n,
00081 const _CharT* __fmt, ...)
00082 {
00083
00084
00085 _CharT* __s = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00086 * __n));
00087
00088 __builtin_va_list __args;
00089 __builtin_va_start(__args, __fmt);
00090
00091 const int __len = __convf(__s, __n, __fmt, __args);
00092
00093 __builtin_va_end(__args);
00094
00095 return _String(__s, __s + __len);
00096 }
00097
00098 _GLIBCXX_END_NAMESPACE_VERSION
00099 }
00100
00101 #endif // _STRING_CONVERSIONS_H