summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/include/locale
diff options
context:
space:
mode:
authortheraven <theraven@FreeBSD.org>2012-03-14 00:09:36 +0000
committertheraven <theraven@FreeBSD.org>2012-03-14 00:09:36 +0000
commit7bd22d0949674b61e2c1a97cbb6caeeb5ab7fd19 (patch)
tree077f044b08d256dd8348f977fe56d18c08fccd78 /contrib/libc++/include/locale
parentd83b894ff4280333de5ef40496cfd061b515ba54 (diff)
parentbaa75b9984d33ea49ffb76a73507b64d879166cc (diff)
downloadFreeBSD-src-7bd22d0949674b61e2c1a97cbb6caeeb5ab7fd19.zip
FreeBSD-src-7bd22d0949674b61e2c1a97cbb6caeeb5ab7fd19.tar.gz
Import new versions of libcxxrt and libc++.
Please tests any C++ code you care about with -stdlib=libc++! Approved by: dim (mentor)
Diffstat (limited to 'contrib/libc++/include/locale')
-rw-r--r--contrib/libc++/include/locale137
1 files changed, 88 insertions, 49 deletions
diff --git a/contrib/libc++/include/locale b/contrib/libc++/include/locale
index b2afbd4..bec27f6 100644
--- a/contrib/libc++/include/locale
+++ b/contrib/libc++/include/locale
@@ -192,6 +192,8 @@ template <class charT> class messages_byname;
#include <nl_types.h>
#endif // !_WIN32
+#include <__undef_min_max>
+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
@@ -209,7 +211,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
typedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr;
+#ifndef _LIBCPP_LOCALE__L_EXTENSIONS
typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
+#endif
// OSX has nice foo_l() functions that let you turn off use of the global
// locale. Linux, not so much. The following functions avoid the locale when
@@ -431,7 +435,7 @@ __scan_keyword(_InputIterator& __b, _InputIterator __e,
bool __case_sensitive = true)
{
typedef typename iterator_traits<_InputIterator>::value_type _CharT;
- size_t __nkw = _VSTD::distance(__kb, __ke);
+ size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke));
const unsigned char __doesnt_match = '\0';
const unsigned char __might_match = '\1';
const unsigned char __does_match = '\2';
@@ -596,7 +600,7 @@ __num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*&
__dc = 0;
return 0;
}
- if (__ct == __thousands_sep && __grouping.size() != 0)
+ if (__grouping.size() != 0 && __ct == __thousands_sep)
{
if (__g_end-__g < __num_get_buf_sz)
{
@@ -663,6 +667,15 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex
if (__f >= 32)
return -1;
char __x = __src[__f];
+ if (__x == '-' || __x == '+')
+ {
+ if (__a_end == __a || (__a_end[-1] & 0xDF) == __exp)
+ {
+ *__a_end++ = __x;
+ return 0;
+ }
+ return -1;
+ }
if (__a_end-__a < __num_get_buf_sz - 1)
*__a_end++ = __x;
if (__x == 'x' || __x == 'X')
@@ -679,8 +692,8 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex
return 0;
}
-extern template class __num_get<char>;
-extern template class __num_get<wchar_t>;
+extern template struct __num_get<char>;
+extern template struct __num_get<wchar_t>;
template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
class _LIBCPP_VISIBLE num_get
@@ -1273,7 +1286,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
int __base = 16;
// Stage 2
char_type __atoms[26];
- char_type __thousands_sep;
+ char_type __thousands_sep = 0;
string __grouping;
use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
__num_get_base::__src + 26, __atoms);
@@ -1451,8 +1464,8 @@ __num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
__op = __ob + (__np - __nb);
}
-extern template class __num_put<char>;
-extern template class __num_put<wchar_t>;
+extern template struct __num_put<char>;
+extern template struct __num_put<wchar_t>;
template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
class _LIBCPP_VISIBLE num_put
@@ -1764,7 +1777,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
unique_ptr<char_type, void(*)(void*)> __obh(0, free);
if (__nb != __nar)
{
- __ob = (char_type*)malloc((2*__nc)*sizeof(char_type));
+ __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
if (__ob == 0)
__throw_bad_alloc();
__obh.reset(__ob);
@@ -1833,7 +1846,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
unique_ptr<char_type, void(*)(void*)> __obh(0, free);
if (__nb != __nar)
{
- __ob = (char_type*)malloc((2*__nc)*sizeof(char_type));
+ __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
if (__ob == 0)
__throw_bad_alloc();
__obh.reset(__ob);
@@ -2100,7 +2113,7 @@ time_get<_CharT, _InputIterator>::__get_weekdayname(int& __w,
{
// Note: ignoring case comes from the POSIX strptime spec
const string_type* __wk = this->__weeks();
- int __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
+ ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
if (__i < 14)
__w = __i % 7;
}
@@ -2114,7 +2127,7 @@ time_get<_CharT, _InputIterator>::__get_monthname(int& __m,
{
// Note: ignoring case comes from the POSIX strptime spec
const string_type* __month = this->__months();
- int __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
+ ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
if (__i < 24)
__m = __i % 12;
}
@@ -2286,7 +2299,7 @@ time_get<_CharT, _InputIterator>::__get_am_pm(int& __h,
__err |= ios_base::failbit;
return;
}
- int __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
+ ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
if (__i == 0 && __h == 12)
__h = 0;
else if (__i == 1 && __h < 12)
@@ -2395,7 +2408,6 @@ time_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e,
ios_base::iostate& __err,
tm* __tm) const
{
- const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
const string_type& __fmt = this->__x();
return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
}
@@ -2458,8 +2470,8 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
break;
case 'c':
{
- const string_type& __fmt = this->__c();
- __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
+ const string_type& __fm = this->__c();
+ __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
}
break;
case 'd':
@@ -2468,14 +2480,14 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
break;
case 'D':
{
- const char_type __fmt[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
- __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+ const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
+ __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'F':
{
- const char_type __fmt[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
- __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+ const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
+ __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'H':
@@ -2502,14 +2514,14 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
break;
case 'r':
{
- const char_type __fmt[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
- __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+ const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
+ __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'R':
{
- const char_type __fmt[] = {'%', 'H', ':', '%', 'M'};
- __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+ const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
+ __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'S':
@@ -2517,8 +2529,8 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
break;
case 'T':
{
- const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
- __b = get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
+ const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
+ __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'w':
@@ -2528,8 +2540,8 @@ time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
return do_get_date(__b, __e, __iob, __err, __tm);
case 'X':
{
- const string_type& __fmt = this->__X();
- __b = get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
+ const string_type& __fm = this->__X();
+ __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
}
break;
case 'y':
@@ -2732,7 +2744,7 @@ time_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob,
template <class _CharT, class _OutputIterator>
_OutputIterator
-time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
+time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
char_type, const tm* __tm,
char __fmt, char __mod) const
{
@@ -3009,10 +3021,10 @@ void
__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e)
{
bool __owns = __b.get_deleter() != __do_nothing;
- size_t __cur_cap = (__e-__b.get()) * sizeof(_Tp);
+ size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp);
size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ?
2 * __cur_cap : numeric_limits<size_t>::max();
- size_t __n_off = __n - __b.get();
+ size_t __n_off = static_cast<size_t>(__n - __b.get());
_Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap);
if (__t == 0)
__throw_bad_alloc();
@@ -3048,6 +3060,9 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
string_type __sym;
string_type __psn;
string_type __nsn;
+ // Capture the spaces read into money_base::{space,none} so they
+ // can be compared to initial spaces in __sym.
+ string_type __spaces;
int __fd;
__money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp,
__sym, __psn, __nsn, __fd);
@@ -3061,7 +3076,7 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
if (__p != 3)
{
if (__ct.is(ctype_base::space, *__b))
- ++__b;
+ __spaces.push_back(*__b++);
else
{
__err |= ios_base::failbit;
@@ -3073,7 +3088,7 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
if (__p != 3)
{
while (__b != __e && __ct.is(ctype_base::space, *__b))
- ++__b;
+ __spaces.push_back(*__b++);
}
break;
case money_base::sign:
@@ -3132,9 +3147,31 @@ money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
if (__sb || __more_needed)
{
ios_base::iostate __et = ios_base::goodbit;
- string_type* __k = __scan_keyword(__b, __e, &__sym, &__sym+1,
- __ct, __et);
- if (__sb && __k != &__sym)
+ typename string_type::const_iterator __sym_space_end = __sym.begin();
+ if (__p > 0 && (__pat.field[__p - 1] == money_base::none ||
+ __pat.field[__p - 1] == money_base::space)) {
+ // Match spaces we've already read against spaces at
+ // the beginning of __sym.
+ while (__sym_space_end != __sym.end() &&
+ __ct.is(ctype_base::space, *__sym_space_end))
+ ++__sym_space_end;
+ const size_t __num_spaces = __sym_space_end - __sym.begin();
+ if (__num_spaces > __spaces.size() ||
+ !equal(__spaces.end() - __num_spaces, __spaces.end(),
+ __sym.begin())) {
+ // No match. Put __sym_space_end back at the
+ // beginning of __sym, which will prevent a
+ // match in the next loop.
+ __sym_space_end = __sym.begin();
+ }
+ }
+ typename string_type::const_iterator __sym_curr_char = __sym_space_end;
+ while (__sym_curr_char != __sym.end() && __b != __e &&
+ *__b == *__sym_curr_char) {
+ ++__b;
+ ++__sym_curr_char;
+ }
+ if (__sb && __sym_curr_char != __sym.end())
{
__err |= ios_base::failbit;
return false;
@@ -3230,7 +3267,7 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
ios_base::iostate& __err,
long double& __v) const
{
- const unsigned __bz = 100;
+ const int __bz = 100;
char_type __wbuf[__bz];
unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
char_type* __wn;
@@ -3249,7 +3286,7 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
unique_ptr<char, void(*)(void*)> __h(0, free);
if (__wn - __wb.get() > __bz-2)
{
- __h.reset((char*)malloc(__wn - __wb.get() + 2));
+ __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
if (__h.get() == 0)
__throw_bad_alloc();
__nc = __h.get();
@@ -3274,7 +3311,7 @@ money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
ios_base::iostate& __err,
string_type& __v) const
{
- const unsigned __bz = 100;
+ const int __bz = 100;
char_type __wbuf[__bz];
unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
char_type* __wn;
@@ -3534,14 +3571,14 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
char* __bb = __buf;
char_type __digits[__bs];
char_type* __db = __digits;
- size_t __n = snprintf(__bb, __bs, "%.0Lf", __units);
+ size_t __n = static_cast<size_t>(snprintf(__bb, __bs, "%.0Lf", __units));
unique_ptr<char, void(*)(void*)> __hn(0, free);
unique_ptr<char_type, void(*)(void*)> __hd(0, free);
// secure memory for digit storage
if (__n > __bs-1)
{
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- __n = asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
+ __n = static_cast<size_t>(asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units));
#else
__n = __asprintf_l(&__bb, __cloc(), "%.0Lf", __units);
#endif
@@ -3549,7 +3586,7 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
__throw_bad_alloc();
__hn.reset(__bb);
__hd.reset((char_type*)malloc(__n * sizeof(char_type)));
- if (__hd == 0)
+ if (__hd == nullptr)
__throw_bad_alloc();
__db = __hd.get();
}
@@ -3571,8 +3608,9 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
char_type* __mb = __mbuf;
unique_ptr<char_type, void(*)(void*)> __hw(0, free);
size_t __exn = static_cast<int>(__n) > __fd ?
- (__n - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1
- : __sn.size() + __sym.size() + __fd + 2;
+ (__n - static_cast<size_t>(__fd)) * 2 + __sn.size() +
+ __sym.size() + static_cast<size_t>(__fd) + 1
+ : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
if (__exn > __bs)
{
__hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
@@ -3611,9 +3649,10 @@ money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
char_type __mbuf[100];
char_type* __mb = __mbuf;
unique_ptr<char_type, void(*)(void*)> __h(0, free);
- size_t __exn = __digits.size() > __fd ?
- (__digits.size() - __fd) * 2 + __sn.size() + __sym.size() + __fd + 1
- : __sn.size() + __sym.size() + __fd + 2;
+ size_t __exn = static_cast<int>(__digits.size()) > __fd ?
+ (__digits.size() - static_cast<size_t>(__fd)) * 2 +
+ __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1
+ : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
if (__exn > 100)
{
__h.reset((char_type*)malloc(__exn * sizeof(char_type)));
@@ -4003,9 +4042,9 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
}
else if (__r == codecvt_base::partial)
{
- ptrdiff_t __s = __to_nxt - &__bs[0];
- __bs.resize(2 * __s);
- __to = &__bs[0] + __s;
+ ptrdiff_t __sp = __to_nxt - &__bs[0];
+ __bs.resize(2 * __sp);
+ __to = &__bs[0] + __sp;
__to_end = &__bs[0] + __bs.size();
}
} while (__r == codecvt_base::partial);
OpenPOWER on IntegriCloud