// Locale support -*- C++ -*-
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007
-// Free Software Foundation, Inc.
+// Copyright (C) 1997-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/** @file locale_facets.tcc
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file bits/locale_facets.tcc
* This is an internal header file, included by other library headers.
- * You should not attempt to use it directly.
+ * Do not attempt to use it directly. @headername{locale}
*/
#ifndef _LOCALE_FACETS_TCC
#pragma GCC system_header
-_GLIBCXX_BEGIN_NAMESPACE(std)
-
- template<typename _Facet>
- locale
- locale::combine(const locale& __other) const
- {
- _Impl* __tmp = new _Impl(*_M_impl, 1);
- try
- {
- __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
- }
- catch(...)
- {
- __tmp->_M_remove_reference();
- __throw_exception_again;
- }
- return locale(__tmp);
- }
-
- template<typename _CharT, typename _Traits, typename _Alloc>
- bool
- locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
- const basic_string<_CharT, _Traits, _Alloc>& __s2) const
- {
- typedef std::collate<_CharT> __collate_type;
- const __collate_type& __collate = use_facet<__collate_type>(*this);
- return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
- __s2.data(), __s2.data() + __s2.length()) < 0);
- }
-
- /**
- * @brief Test for the presence of a facet.
- *
- * has_facet tests the locale argument for the presence of the facet type
- * provided as the template parameter. Facets derived from the facet
- * parameter will also return true.
- *
- * @param Facet The facet type to test the presence of.
- * @param locale The locale to test.
- * @return true if locale contains a facet of type Facet, else false.
- */
- template<typename _Facet>
- inline bool
- has_facet(const locale& __loc) throw()
- {
- const size_t __i = _Facet::id._M_id();
- const locale::facet** __facets = __loc._M_impl->_M_facets;
- return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
- }
-
- /**
- * @brief Return a facet.
- *
- * use_facet looks for and returns a reference to a facet of type Facet
- * where Facet is the template parameter. If has_facet(locale) is true,
- * there is a suitable facet to return. It throws std::bad_cast if the
- * locale doesn't contain a facet of type Facet.
- *
- * @param Facet The facet type to access.
- * @param locale The locale to use.
- * @return Reference to facet of type Facet.
- * @throw std::bad_cast if locale doesn't contain a facet of type Facet.
- */
- template<typename _Facet>
- inline const _Facet&
- use_facet(const locale& __loc)
- {
- const size_t __i = _Facet::id._M_id();
- const locale::facet** __facets = __loc._M_impl->_M_facets;
- if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
- __throw_bad_cast();
- return static_cast<const _Facet&>(*__facets[__i]);
- }
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
// Routine to access a cache for the facet. If the cache didn't
// exist before, it gets constructed on the fly.
const locale::facet** __caches = __loc._M_impl->_M_caches;
if (!__caches[__i])
{
- __numpunct_cache<_CharT>* __tmp = NULL;
- try
+ __numpunct_cache<_CharT>* __tmp = 0;
+ __try
{
__tmp = new __numpunct_cache<_CharT>;
__tmp->_M_cache(__loc);
}
- catch(...)
+ __catch(...)
{
delete __tmp;
__throw_exception_again;
void
__numpunct_cache<_CharT>::_M_cache(const locale& __loc)
{
- _M_allocated = true;
-
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
- _M_grouping_size = __np.grouping().size();
- char* __grouping = new char[_M_grouping_size];
- __np.grouping().copy(__grouping, _M_grouping_size);
- _M_grouping = __grouping;
- _M_use_grouping = (_M_grouping_size
- && static_cast<signed char>(__np.grouping()[0]) > 0);
-
- _M_truename_size = __np.truename().size();
- _CharT* __truename = new _CharT[_M_truename_size];
- __np.truename().copy(__truename, _M_truename_size);
- _M_truename = __truename;
-
- _M_falsename_size = __np.falsename().size();
- _CharT* __falsename = new _CharT[_M_falsename_size];
- __np.falsename().copy(__falsename, _M_falsename_size);
- _M_falsename = __falsename;
-
- _M_decimal_point = __np.decimal_point();
- _M_thousands_sep = __np.thousands_sep();
-
- const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
- __ct.widen(__num_base::_S_atoms_out,
- __num_base::_S_atoms_out + __num_base::_S_oend, _M_atoms_out);
- __ct.widen(__num_base::_S_atoms_in,
- __num_base::_S_atoms_in + __num_base::_S_iend, _M_atoms_in);
+ char* __grouping = 0;
+ _CharT* __truename = 0;
+ _CharT* __falsename = 0;
+ __try
+ {
+ const string& __g = __np.grouping();
+ _M_grouping_size = __g.size();
+ __grouping = new char[_M_grouping_size];
+ __g.copy(__grouping, _M_grouping_size);
+ _M_use_grouping = (_M_grouping_size
+ && static_cast<signed char>(__grouping[0]) > 0
+ && (__grouping[0]
+ != __gnu_cxx::__numeric_traits<char>::__max));
+
+ const basic_string<_CharT>& __tn = __np.truename();
+ _M_truename_size = __tn.size();
+ __truename = new _CharT[_M_truename_size];
+ __tn.copy(__truename, _M_truename_size);
+
+ const basic_string<_CharT>& __fn = __np.falsename();
+ _M_falsename_size = __fn.size();
+ __falsename = new _CharT[_M_falsename_size];
+ __fn.copy(__falsename, _M_falsename_size);
+
+ _M_decimal_point = __np.decimal_point();
+ _M_thousands_sep = __np.thousands_sep();
+
+ const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc);
+ __ct.widen(__num_base::_S_atoms_out,
+ __num_base::_S_atoms_out
+ + __num_base::_S_oend, _M_atoms_out);
+ __ct.widen(__num_base::_S_atoms_in,
+ __num_base::_S_atoms_in
+ + __num_base::_S_iend, _M_atoms_in);
+
+ _M_grouping = __grouping;
+ _M_truename = __truename;
+ _M_falsename = __falsename;
+ _M_allocated = true;
+ }
+ __catch(...)
+ {
+ delete [] __grouping;
+ delete [] __truename;
+ delete [] __falsename;
+ __throw_exception_again;
+ }
}
// Used by both numeric and monetary facets.
// 1,222,444 == __grouping_tmp of "\1\3\3"
// __grouping is parsed R to L
// 1,222,444 == __grouping of "\3" == "\3\3\3"
- static bool
+ _GLIBCXX_PURE bool
__verify_grouping(const char* __grouping, size_t __grouping_size,
- const string& __grouping_tmp);
+ const string& __grouping_tmp) throw ();
-_GLIBCXX_BEGIN_LDBL_NAMESPACE
+_GLIBCXX_BEGIN_NAMESPACE_LDBL
template<typename _CharT, typename _InIter>
+ _GLIBCXX_DEFAULT_ABI_TAG
_InIter
num_get<_CharT, _InIter>::
_M_extract_float(_InIter __beg, _InIter __end, ios_base& __io,
if (!std::__verify_grouping(__lc->_M_grouping,
__lc->_M_grouping_size,
__found_grouping))
- __err |= ios_base::failbit;
+ __err = ios_base::failbit;
}
- // Finish up.
- if (__testeof)
- __err |= ios_base::eofbit;
return __beg;
}
template<typename _CharT, typename _InIter>
template<typename _ValueT>
+ _GLIBCXX_DEFAULT_ABI_TAG
_InIter
num_get<_CharT, _InIter>::
_M_extract_int(_InIter __beg, _InIter __end, ios_base& __io,
if (!__testeof)
{
__c = *__beg;
- if (__gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
- __negative = __c == __lit[__num_base::_S_iminus];
+ __negative = __c == __lit[__num_base::_S_iminus];
if ((__negative || __c == __lit[__num_base::_S_iplus])
&& !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
&& !(__c == __lc->_M_decimal_point))
if (__lc->_M_use_grouping)
__found_grouping.reserve(32);
bool __testfail = false;
- const __unsigned_type __max = __negative
+ bool __testoverflow = false;
+ const __unsigned_type __max =
+ (__negative && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
? -__gnu_cxx::__numeric_traits<_ValueT>::__min
: __gnu_cxx::__numeric_traits<_ValueT>::__max;
const __unsigned_type __smax = __max / __base;
break;
if (__result > __smax)
- __testfail = true;
+ __testoverflow = true;
else
{
__result *= __base;
- __testfail |= __result > __max - __digit;
+ __testoverflow |= __result > __max - __digit;
__result += __digit;
++__sep_pos;
}
if (__digit > 15)
__digit -= 6;
if (__result > __smax)
- __testfail = true;
+ __testoverflow = true;
else
{
__result *= __base;
- __testfail |= __result > __max - __digit;
+ __testoverflow |= __result > __max - __digit;
__result += __digit;
++__sep_pos;
}
if (!std::__verify_grouping(__lc->_M_grouping,
__lc->_M_grouping_size,
__found_grouping))
- __err |= ios_base::failbit;
+ __err = ios_base::failbit;
}
- if (!__testfail && (__sep_pos || __found_zero
- || __found_grouping.size()))
- __v = __negative ? -__result : __result;
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 23. Num_get overflow result.
+ if ((!__sep_pos && !__found_zero && !__found_grouping.size())
+ || __testfail)
+ {
+ __v = 0;
+ __err = ios_base::failbit;
+ }
+ else if (__testoverflow)
+ {
+ if (__negative
+ && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
+ __v = __gnu_cxx::__numeric_traits<_ValueT>::__min;
+ else
+ __v = __gnu_cxx::__numeric_traits<_ValueT>::__max;
+ __err = ios_base::failbit;
+ }
else
- __err |= ios_base::failbit;
+ __v = __negative ? -__result : __result;
if (__testeof)
__err |= ios_base::eofbit;
if (__l == 0 || __l == 1)
__v = bool(__l);
else
- __err |= ios_base::failbit;
+ {
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 23. Num_get overflow result.
+ __v = true;
+ __err = ios_base::failbit;
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
+ }
}
else
{
// Parse bool values as alphanumeric.
- typedef __numpunct_cache<_CharT> __cache_type;
+ typedef __numpunct_cache<_CharT> __cache_type;
__use_cache<__cache_type> __uc;
const locale& __loc = __io._M_getloc();
const __cache_type* __lc = __uc(__loc);
bool __testf = true;
bool __testt = true;
- size_t __n;
- bool __testeof = __beg == __end;
- for (__n = 0; !__testeof; ++__n)
- {
- const char_type __c = *__beg;
-
- if (__testf)
- {
- if (__n < __lc->_M_falsename_size)
- __testf = __c == __lc->_M_falsename[__n];
- else
- break;
- }
-
- if (__testt)
- {
- if (__n < __lc->_M_truename_size)
- __testt = __c == __lc->_M_truename[__n];
- else
- break;
+ bool __donef = __lc->_M_falsename_size == 0;
+ bool __donet = __lc->_M_truename_size == 0;
+ bool __testeof = false;
+ size_t __n = 0;
+ while (!__donef || !__donet)
+ {
+ if (__beg == __end)
+ {
+ __testeof = true;
+ break;
}
- if (!__testf && !__testt)
- break;
-
- if (++__beg == __end)
- __testeof = true;
- }
- if (__testf && __n == __lc->_M_falsename_size)
- __v = false;
- else if (__testt && __n == __lc->_M_truename_size)
- __v = true;
- else
- __err |= ios_base::failbit;
+ const char_type __c = *__beg;
- if (__testeof)
- __err |= ios_base::eofbit;
- }
- return __beg;
- }
+ if (!__donef)
+ __testf = __c == __lc->_M_falsename[__n];
- template<typename _CharT, typename _InIter>
- _InIter
- num_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, ios_base& __io,
- ios_base::iostate& __err, long& __v) const
- { return _M_extract_int(__beg, __end, __io, __err, __v); }
+ if (!__testf && __donet)
+ break;
- template<typename _CharT, typename _InIter>
- _InIter
- num_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, ios_base& __io,
- ios_base::iostate& __err, unsigned short& __v) const
- { return _M_extract_int(__beg, __end, __io, __err, __v); }
+ if (!__donet)
+ __testt = __c == __lc->_M_truename[__n];
- template<typename _CharT, typename _InIter>
- _InIter
- num_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, ios_base& __io,
- ios_base::iostate& __err, unsigned int& __v) const
- { return _M_extract_int(__beg, __end, __io, __err, __v); }
+ if (!__testt && __donef)
+ break;
- template<typename _CharT, typename _InIter>
- _InIter
- num_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, ios_base& __io,
- ios_base::iostate& __err, unsigned long& __v) const
- { return _M_extract_int(__beg, __end, __io, __err, __v); }
+ if (!__testt && !__testf)
+ break;
-#ifdef _GLIBCXX_USE_LONG_LONG
- template<typename _CharT, typename _InIter>
- _InIter
- num_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, ios_base& __io,
- ios_base::iostate& __err, long long& __v) const
- { return _M_extract_int(__beg, __end, __io, __err, __v); }
+ ++__n;
+ ++__beg;
- template<typename _CharT, typename _InIter>
- _InIter
- num_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, ios_base& __io,
- ios_base::iostate& __err, unsigned long long& __v) const
- { return _M_extract_int(__beg, __end, __io, __err, __v); }
-#endif
+ __donef = !__testf || __n >= __lc->_M_falsename_size;
+ __donet = !__testt || __n >= __lc->_M_truename_size;
+ }
+ if (__testf && __n == __lc->_M_falsename_size && __n)
+ {
+ __v = false;
+ if (__testt && __n == __lc->_M_truename_size)
+ __err = ios_base::failbit;
+ else
+ __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
+ }
+ else if (__testt && __n == __lc->_M_truename_size && __n)
+ {
+ __v = true;
+ __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
+ }
+ else
+ {
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 23. Num_get overflow result.
+ __v = false;
+ __err = ios_base::failbit;
+ if (__testeof)
+ __err |= ios_base::eofbit;
+ }
+ }
+ return __beg;
+ }
template<typename _CharT, typename _InIter>
_InIter
__xtrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
return __beg;
}
__xtrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
return __beg;
}
__xtrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
return __beg;
}
#endif
__xtrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
return __beg;
}
// Reset from hex formatted input.
__io.flags(__fmt);
- if (!(__err & ios_base::failbit))
- __v = reinterpret_cast<void*>(__ul);
+ __v = reinterpret_cast<void*>(__ul);
return __beg;
}
__len = static_cast<int>(__w);
}
-_GLIBCXX_END_LDBL_NAMESPACE
+_GLIBCXX_END_NAMESPACE_LDBL
template<typename _CharT, typename _ValueT>
int
return __bufend - __buf;
}
-_GLIBCXX_BEGIN_LDBL_NAMESPACE
+_GLIBCXX_BEGIN_NAMESPACE_LDBL
template<typename _CharT, typename _OutIter>
void
if (__builtin_expect(__dec, true))
{
// Decimal.
- if (__v > 0)
+ if (__v >= 0)
{
- if (__flags & ios_base::showpos
+ if (bool(__flags & ios_base::showpos)
&& __gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
*--__cs = __lit[__num_base::_S_oplus], ++__len;
}
- else if (__v)
+ else
*--__cs = __lit[__num_base::_S_ominus], ++__len;
}
- else if (__flags & ios_base::showbase && __v)
+ else if (bool(__flags & ios_base::showbase) && __v)
{
if (__basefield == ios_base::oct)
*--__cs = __lit[__num_base::_S_odigits], ++__len;
__num_base::_S_format_float(__io, __fbuf, __mod);
#ifdef _GLIBCXX_USE_C99
+ // Precision is always used except for hexfloat format.
+ const bool __use_prec =
+ (__io.flags() & ios_base::floatfield) != ios_base::floatfield;
+
// First try a buffer perhaps big enough (most probably sufficient
// for non-ios_base::fixed outputs)
int __cs_size = __max_digits * 3;
char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
- __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
- __fbuf, __prec, __v);
+ if (__use_prec)
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+ __fbuf, __prec, __v);
+ else
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+ __fbuf, __v);
// If the buffer was not large enough, try again with the correct size.
if (__len >= __cs_size)
{
__cs_size = __len + 1;
__cs = static_cast<char*>(__builtin_alloca(__cs_size));
- __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
- __fbuf, __prec, __v);
+ if (__use_prec)
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+ __fbuf, __prec, __v);
+ else
+ __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
+ __fbuf, __v);
}
#else
// Consider the possibility of long ios_base::fixed outputs
const streamsize __w = __io.width();
if (__w > static_cast<streamsize>(__len))
{
- _CharT* __cs
+ const streamsize __plen = __w - __len;
+ _CharT* __ps
= static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
- * __w));
- _M_pad(__fill, __w, __io, __cs, __name, __len);
- __name = __cs;
+ * __plen));
+
+ char_traits<_CharT>::assign(__ps, __plen, __fill);
+ __io.width(0);
+
+ if ((__flags & ios_base::adjustfield) == ios_base::left)
+ {
+ __s = std::__write(__s, __name, __len);
+ __s = std::__write(__s, __ps, __plen);
+ }
+ else
+ {
+ __s = std::__write(__s, __ps, __plen);
+ __s = std::__write(__s, __name, __len);
+ }
+ return __s;
}
__io.width(0);
__s = std::__write(__s, __name, __len);
return __s;
}
- template<typename _CharT, typename _OutIter>
- _OutIter
- num_put<_CharT, _OutIter>::
- do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
- { return _M_insert_int(__s, __io, __fill, __v); }
-
- template<typename _CharT, typename _OutIter>
- _OutIter
- num_put<_CharT, _OutIter>::
- do_put(iter_type __s, ios_base& __io, char_type __fill,
- unsigned long __v) const
- { return _M_insert_int(__s, __io, __fill, __v); }
-
-#ifdef _GLIBCXX_USE_LONG_LONG
- template<typename _CharT, typename _OutIter>
- _OutIter
- num_put<_CharT, _OutIter>::
- do_put(iter_type __s, ios_base& __io, char_type __fill, long long __v) const
- { return _M_insert_int(__s, __io, __fill, __v); }
-
- template<typename _CharT, typename _OutIter>
- _OutIter
- num_put<_CharT, _OutIter>::
- do_put(iter_type __s, ios_base& __io, char_type __fill,
- unsigned long long __v) const
- { return _M_insert_int(__s, __io, __fill, __v); }
-#endif
-
template<typename _CharT, typename _OutIter>
_OutIter
num_put<_CharT, _OutIter>::
{
const ios_base::fmtflags __flags = __io.flags();
const ios_base::fmtflags __fmt = ~(ios_base::basefield
- | ios_base::uppercase
- | ios_base::internal);
+ | ios_base::uppercase);
__io.flags((__flags & __fmt) | (ios_base::hex | ios_base::showbase));
typedef __gnu_cxx::__conditional_type<(sizeof(const void*)
return __s;
}
-_GLIBCXX_END_LDBL_NAMESPACE
-
- // Generic version does nothing.
- template<typename _CharT>
- int
- collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const
- { return 0; }
-
- // Generic version does nothing.
- template<typename _CharT>
- size_t
- collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const
- { return 0; }
-
- template<typename _CharT>
- int
- collate<_CharT>::
- do_compare(const _CharT* __lo1, const _CharT* __hi1,
- const _CharT* __lo2, const _CharT* __hi2) const
- {
- // strcoll assumes zero-terminated strings so we make a copy
- // and then put a zero at the end.
- const string_type __one(__lo1, __hi1);
- const string_type __two(__lo2, __hi2);
-
- const _CharT* __p = __one.c_str();
- const _CharT* __pend = __one.data() + __one.length();
- const _CharT* __q = __two.c_str();
- const _CharT* __qend = __two.data() + __two.length();
-
- // strcoll stops when it sees a nul character so we break
- // the strings into zero-terminated substrings and pass those
- // to strcoll.
- for (;;)
- {
- const int __res = _M_compare(__p, __q);
- if (__res)
- return __res;
-
- __p += char_traits<_CharT>::length(__p);
- __q += char_traits<_CharT>::length(__q);
- if (__p == __pend && __q == __qend)
- return 0;
- else if (__p == __pend)
- return -1;
- else if (__q == __qend)
- return 1;
-
- __p++;
- __q++;
- }
- }
-
- template<typename _CharT>
- typename collate<_CharT>::string_type
- collate<_CharT>::
- do_transform(const _CharT* __lo, const _CharT* __hi) const
- {
- string_type __ret;
-
- // strxfrm assumes zero-terminated strings so we make a copy
- const string_type __str(__lo, __hi);
-
- const _CharT* __p = __str.c_str();
- const _CharT* __pend = __str.data() + __str.length();
-
- size_t __len = (__hi - __lo) * 2;
-
- _CharT* __c = new _CharT[__len];
-
- try
- {
- // strxfrm stops when it sees a nul character so we break
- // the string into zero-terminated substrings and pass those
- // to strxfrm.
- for (;;)
- {
- // First try a buffer perhaps big enough.
- size_t __res = _M_transform(__c, __p, __len);
- // If the buffer was not large enough, try again with the
- // correct size.
- if (__res >= __len)
- {
- __len = __res + 1;
- delete [] __c, __c = 0;
- __c = new _CharT[__len];
- __res = _M_transform(__c, __p, __len);
- }
-
- __ret.append(__c, __res);
- __p += char_traits<_CharT>::length(__p);
- if (__p == __pend)
- break;
-
- __p++;
- __ret.push_back(_CharT());
- }
- }
- catch(...)
- {
- delete [] __c;
- __throw_exception_again;
- }
-
- delete [] __c;
-
- return __ret;
- }
-
- template<typename _CharT>
- long
- collate<_CharT>::
- do_hash(const _CharT* __lo, const _CharT* __hi) const
- {
- unsigned long __val = 0;
- for (; __lo < __hi; ++__lo)
- __val =
- *__lo + ((__val << 7)
- | (__val >> (__gnu_cxx::__numeric_traits<unsigned long>::
- __digits - 7)));
- return static_cast<long>(__val);
- }
+_GLIBCXX_END_NAMESPACE_LDBL
// Construct correctly padded string, as per 22.2.2.2.2
// Assumes
void
__pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill,
_CharT* __news, const _CharT* __olds,
- const streamsize __newlen,
- const streamsize __oldlen)
+ streamsize __newlen, streamsize __oldlen)
{
const size_t __plen = static_cast<size_t>(__newlen - __oldlen);
const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
// Padding last.
if (__adjust == ios_base::left)
{
- _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen);
+ _Traits::copy(__news, __olds, __oldlen);
_Traits::assign(__news + __oldlen, __plen, __fill);
return;
}
const locale& __loc = __io._M_getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
- const bool __testsign = (__ctype.widen('-') == __olds[0]
- || __ctype.widen('+') == __olds[0]);
- const bool __testhex = (__ctype.widen('0') == __olds[0]
- && __oldlen > 1
- && (__ctype.widen('x') == __olds[1]
- || __ctype.widen('X') == __olds[1]));
- if (__testhex)
+ if (__ctype.widen('-') == __olds[0]
+ || __ctype.widen('+') == __olds[0])
{
__news[0] = __olds[0];
- __news[1] = __olds[1];
- __mod = 2;
- __news += 2;
+ __mod = 1;
+ ++__news;
}
- else if (__testsign)
+ else if (__ctype.widen('0') == __olds[0]
+ && __oldlen > 1
+ && (__ctype.widen('x') == __olds[1]
+ || __ctype.widen('X') == __olds[1]))
{
__news[0] = __olds[0];
- __mod = 1;
- ++__news;
+ __news[1] = __olds[1];
+ __mod = 2;
+ __news += 2;
}
// else Padding first.
}
_Traits::assign(__news, __plen, __fill);
- _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod),
- __oldlen - __mod);
+ _Traits::copy(__news + __plen, __olds + __mod, __oldlen - __mod);
}
- bool
- __verify_grouping(const char* __grouping, size_t __grouping_size,
- const string& __grouping_tmp)
- {
- const size_t __n = __grouping_tmp.size() - 1;
- const size_t __min = std::min(__n, size_t(__grouping_size - 1));
- size_t __i = __n;
- bool __test = true;
-
- // Parsed number groupings have to match the
- // numpunct::grouping string exactly, starting at the
- // right-most point of the parsed sequence of elements ...
- for (size_t __j = 0; __j < __min && __test; --__i, ++__j)
- __test = __grouping_tmp[__i] == __grouping[__j];
- for (; __i && __test; --__i)
- __test = __grouping_tmp[__i] == __grouping[__min];
- // ... but the first parsed grouping can be <= numpunct
- // grouping (only do the check if the numpunct char is > 0
- // because <= 0 means any size is ok).
- if (static_cast<signed char>(__grouping[__min]) > 0)
- __test &= __grouping_tmp[0] <= __grouping[__min];
- return __test;
- }
-
template<typename _CharT>
_CharT*
__add_grouping(_CharT* __s, _CharT __sep,
size_t __ctr = 0;
while (__last - __first > __gbeg[__idx]
- && static_cast<signed char>(__gbeg[__idx]) > 0)
+ && static_cast<signed char>(__gbeg[__idx]) > 0
+ && __gbeg[__idx] != __gnu_cxx::__numeric_traits<char>::__max)
{
__last -= __gbeg[__idx];
__idx < __gsize - 1 ? ++__idx : ++__ctr;
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
- // NB: This syntax is a GNU extension.
#if _GLIBCXX_EXTERN_TEMPLATE
- extern template class numpunct<char>;
- extern template class numpunct_byname<char>;
- extern template class _GLIBCXX_LDBL_NAMESPACE num_get<char>;
- extern template class _GLIBCXX_LDBL_NAMESPACE num_put<char>;
+ extern template class _GLIBCXX_NAMESPACE_CXX11 numpunct<char>;
+ extern template class _GLIBCXX_NAMESPACE_CXX11 numpunct_byname<char>;
+ extern template class _GLIBCXX_NAMESPACE_LDBL num_get<char>;
+ extern template class _GLIBCXX_NAMESPACE_LDBL num_put<char>;
extern template class ctype_byname<char>;
- extern template class codecvt_byname<char, char, mbstate_t>;
- extern template class collate<char>;
- extern template class collate_byname<char>;
-
- extern template
- const codecvt<char, char, mbstate_t>&
- use_facet<codecvt<char, char, mbstate_t> >(const locale&);
extern template
- const collate<char>&
- use_facet<collate<char> >(const locale&);
+ const ctype<char>&
+ use_facet<ctype<char> >(const locale&);
extern template
const numpunct<char>&
bool
has_facet<ctype<char> >(const locale&);
- extern template
- bool
- has_facet<codecvt<char, char, mbstate_t> >(const locale&);
-
- extern template
- bool
- has_facet<collate<char> >(const locale&);
-
extern template
bool
has_facet<numpunct<char> >(const locale&);
has_facet<num_get<char> >(const locale&);
#ifdef _GLIBCXX_USE_WCHAR_T
- extern template class numpunct<wchar_t>;
- extern template class numpunct_byname<wchar_t>;
- extern template class _GLIBCXX_LDBL_NAMESPACE num_get<wchar_t>;
- extern template class _GLIBCXX_LDBL_NAMESPACE num_put<wchar_t>;
+ extern template class _GLIBCXX_NAMESPACE_CXX11 numpunct<wchar_t>;
+ extern template class _GLIBCXX_NAMESPACE_CXX11 numpunct_byname<wchar_t>;
+ extern template class _GLIBCXX_NAMESPACE_LDBL num_get<wchar_t>;
+ extern template class _GLIBCXX_NAMESPACE_LDBL num_put<wchar_t>;
extern template class ctype_byname<wchar_t>;
- extern template class codecvt_byname<wchar_t, char, mbstate_t>;
- extern template class collate<wchar_t>;
- extern template class collate_byname<wchar_t>;
-
- extern template
- const codecvt<wchar_t, char, mbstate_t>&
- use_facet<codecvt<wchar_t, char, mbstate_t> >(locale const&);
extern template
- const collate<wchar_t>&
- use_facet<collate<wchar_t> >(const locale&);
+ const ctype<wchar_t>&
+ use_facet<ctype<wchar_t> >(const locale&);
extern template
const numpunct<wchar_t>&
bool
has_facet<ctype<wchar_t> >(const locale&);
- extern template
- bool
- has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
-
- extern template
- bool
- has_facet<collate<wchar_t> >(const locale&);
-
extern template
bool
has_facet<numpunct<wchar_t> >(const locale&);
#endif
#endif
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
#endif