]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/ext/string_conversions.h
1 // String Conversions -*- C++ -*-
3 // Copyright (C) 2008 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 #ifndef _STRING_CONVERSIONS_H
31 #define _STRING_CONVERSIONS_H 1
33 #pragma GCC system_header
35 #include <ext/numeric_traits.h>
36 #include <bits/functexcept.h>
43 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx
)
45 // Helper for all the sto* functions.
46 template<typename _TRet
, typename _Ret
= _TRet
, typename _CharT
,
49 __stoa(_TRet (*__convf
) (const _CharT
*, _CharT
**, _Base
...),
50 const char* __name
, const _CharT
* __str
, std::size_t* __idx
,
57 const _TRet __tmp
= __convf(__str
, &__endptr
, __base
...);
59 if (__endptr
== __str
)
60 std::__throw_invalid_argument(__name
);
61 else if (errno
== ERANGE
62 || (std::__are_same
<_Ret
, int>::__value
63 && (__tmp
< __numeric_traits
<int>::__min
64 || __tmp
> __numeric_traits
<int>::__max
)))
65 std::__throw_out_of_range(__name
);
70 *__idx
= __endptr
- __str
;
75 // Helper for the to_string / to_wstring functions.
76 template<typename _String
, typename _CharT
= typename
_String::value_type
>
78 __to_xstring(int (*__convf
) (_CharT
*, std::size_t, const _CharT
*,
79 __builtin_va_list
), std::size_t __n
,
80 const _CharT
* __fmt
, ...)
82 // XXX Eventually the result will be constructed in place in
83 // the C++0x string, likely with the help of internal hooks.
84 _CharT
* __s
= static_cast<_CharT
*>(__builtin_alloca(sizeof(_CharT
)
87 __builtin_va_list __args
;
88 __builtin_va_start(__args
, __fmt
);
90 const int __len
= __convf(__s
, __n
, __fmt
, __args
);
92 __builtin_va_end(__args
);
94 return _String(__s
, __s
+ __len
);
97 _GLIBCXX_END_NAMESPACE
99 #endif // _STRING_CONVERSIONS_H