diff options
author | Paolo Carlini <pcarlini@suse.de> | 2004-01-14 19:14:39 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2004-01-14 19:14:39 +0000 |
commit | 47f62b27c8605658db7658421ef56b8d020ed4fb (patch) | |
tree | ba1d8461de3c6501263580b5bd02455bbd808a51 /libstdc++-v3 | |
parent | 41f24725031f84b841142fb5f9afa58e1e6ae1ff (diff) | |
download | gcc-47f62b27c8605658db7658421ef56b8d020ed4fb.zip gcc-47f62b27c8605658db7658421ef56b8d020ed4fb.tar.gz gcc-47f62b27c8605658db7658421ef56b8d020ed4fb.tar.bz2 |
locale_facets.h (struct __numpunct_cache): Add member _M_grouping_size, caching the length of _M_grouping.
2004-01-14 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (struct __numpunct_cache):
Add member _M_grouping_size, caching the length of _M_grouping.
(__numpunct_cache<>::_M_cache): Assign the latter.
(__verify_grouping): Move declaration...
* include/bits/locale_facets.tcc (__verify_grouping):
... here, change signature to take a const char* and a size_t
for the grouping; not a template anymore.
(__add_grouping, num_put::_M_group_int, num_put::_M_group_float):
Likewise change signature and tweak consistently.
(num_get::_M_extract_float, num_get::_M_extract_int,
num_put::_M_insert_int, num_put::_M_insert_float,
money_get::do_get(string_type&), money_get::do_put(string_type)):
Update callers.
* config/locale/generic/numeric_members.cc
(numpunct<>::_M_initialize_numpunct): Assign the new member.
* config/locale/gnu/numeric_members.cc
(numpunct<>::_M_initialize_numpunct): Likewise.
* src/locale-inst.cc (__add_grouping): Tweak signature.
(__verify_grouping): Don't instantiate, not a template anymore.
* include/bits/locale_facets.h: Rename _M_truename_len ->
_M_truename_size, _M_falsename_len -> _M_falsename_size.
* include/bits/locale_facets.tcc: Likewise.
* config/locale/generic/numeric_members.cc: Likewise.
* config/locale/gnu/numeric_members.cc: Likewise.
From-SVN: r75876
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 28 | ||||
-rw-r--r-- | libstdc++-v3/config/locale/generic/numeric_members.cc | 14 | ||||
-rw-r--r-- | libstdc++-v3/config/locale/gnu/numeric_members.cc | 12 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.h | 63 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.tcc | 85 | ||||
-rw-r--r-- | libstdc++-v3/src/locale-inst.cc | 7 |
6 files changed, 120 insertions, 89 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2afafca..aac5acf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,31 @@ +2004-01-14 Paolo Carlini <pcarlini@suse.de> + + * include/bits/locale_facets.h (struct __numpunct_cache): + Add member _M_grouping_size, caching the length of _M_grouping. + (__numpunct_cache<>::_M_cache): Assign the latter. + (__verify_grouping): Move declaration... + * include/bits/locale_facets.tcc (__verify_grouping): + ... here, change signature to take a const char* and a size_t + for the grouping; not a template anymore. + (__add_grouping, num_put::_M_group_int, num_put::_M_group_float): + Likewise change signature and tweak consistently. + (num_get::_M_extract_float, num_get::_M_extract_int, + num_put::_M_insert_int, num_put::_M_insert_float, + money_get::do_get(string_type&), money_get::do_put(string_type)): + Update callers. + * config/locale/generic/numeric_members.cc + (numpunct<>::_M_initialize_numpunct): Assign the new member. + * config/locale/gnu/numeric_members.cc + (numpunct<>::_M_initialize_numpunct): Likewise. + * src/locale-inst.cc (__add_grouping): Tweak signature. + (__verify_grouping): Don't instantiate, not a template anymore. + + * include/bits/locale_facets.h: Rename _M_truename_len -> + _M_truename_size, _M_falsename_len -> _M_falsename_size. + * include/bits/locale_facets.tcc: Likewise. + * config/locale/generic/numeric_members.cc: Likewise. + * config/locale/gnu/numeric_members.cc: Likewise. + 2004-01-14 Stefan Olsson <stefan@snon.net> * include/ext/mt_allocator.h: Fixups. diff --git a/libstdc++-v3/config/locale/generic/numeric_members.cc b/libstdc++-v3/config/locale/generic/numeric_members.cc index 72760ae..0645865 100644 --- a/libstdc++-v3/config/locale/generic/numeric_members.cc +++ b/libstdc++-v3/config/locale/generic/numeric_members.cc @@ -57,10 +57,12 @@ namespace std for (size_t __i = 0; __i < __num_base::_S_iend; ++__i) _M_data->_M_atoms_in[__i] = __num_base::_S_atoms_in[__i]; + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); + _M_data->_M_truename = "true"; - _M_data->_M_truename_len = strlen(_M_data->_M_truename); + _M_data->_M_truename_size = strlen(_M_data->_M_truename); _M_data->_M_falsename = "false"; - _M_data->_M_falsename_len = strlen(_M_data->_M_falsename); + _M_data->_M_falsename_size = strlen(_M_data->_M_falsename); } template<> @@ -95,11 +97,13 @@ namespace std uc = static_cast<unsigned char>(__num_base::_S_atoms_in[__i]); _M_data->_M_atoms_in[__i] = btowc(uc); } - + + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); + _M_data->_M_truename = L"true"; - _M_data->_M_truename_len = wcslen(_M_data->_M_truename); + _M_data->_M_truename_size = wcslen(_M_data->_M_truename); _M_data->_M_falsename = L"false"; - _M_data->_M_falsename_len = wcslen(_M_data->_M_falsename); + _M_data->_M_falsename_size = wcslen(_M_data->_M_falsename); } template<> diff --git a/libstdc++-v3/config/locale/gnu/numeric_members.cc b/libstdc++-v3/config/locale/gnu/numeric_members.cc index b830456..debee10 100644 --- a/libstdc++-v3/config/locale/gnu/numeric_members.cc +++ b/libstdc++-v3/config/locale/gnu/numeric_members.cc @@ -72,13 +72,15 @@ namespace std else _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc); } + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); + // NB: There is no way to extact this info from posix locales. // _M_truename = __nl_langinfo_l(YESSTR, __cloc); _M_data->_M_truename = "true"; - _M_data->_M_truename_len = strlen(_M_data->_M_truename); + _M_data->_M_truename_size = strlen(_M_data->_M_truename); // _M_falsename = __nl_langinfo_l(NOSTR, __cloc); _M_data->_M_falsename = "false"; - _M_data->_M_falsename_len = strlen(_M_data->_M_falsename); + _M_data->_M_falsename_size = strlen(_M_data->_M_falsename); } template<> @@ -137,13 +139,15 @@ namespace std else _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc); } + _M_data->_M_grouping_size = strlen(_M_data->_M_grouping); + // NB: There is no way to extact this info from posix locales. // _M_truename = __nl_langinfo_l(YESSTR, __cloc); _M_data->_M_truename = L"true"; - _M_data->_M_truename_len = wcslen(_M_data->_M_truename); + _M_data->_M_truename_size = wcslen(_M_data->_M_truename); // _M_falsename = __nl_langinfo_l(NOSTR, __cloc); _M_data->_M_falsename = L"false"; - _M_data->_M_falsename_len = wcslen(_M_data->_M_falsename); + _M_data->_M_falsename_size = wcslen(_M_data->_M_falsename); } template<> diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index 493d3a4..05003ed 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -93,27 +93,14 @@ namespace std }; // Used by both numeric and monetary facets. - // Check to make sure that the __grouping_tmp string constructed in - // money_get or num_get matches the canonical grouping for a given - // locale. - // __grouping_tmp is parsed L to R - // 1,222,444 == __grouping_tmp of "\1\3\3" - // __grouping is parsed R to L - // 1,222,444 == __grouping of "\3" == "\3\3\3" - template<typename _CharT> - bool - __verify_grouping(const basic_string<_CharT>& __grouping, - const basic_string<_CharT>& __grouping_tmp); - - // Used by both numeric and monetary facets. // Inserts "group separator" characters into an array of characters. // It's recursive, one iteration per group. It moves the characters // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this - // only with __gbeg != __gend. + // only with __glen != 0. template<typename _CharT> _CharT* __add_grouping(_CharT* __s, _CharT __sep, - const char* __gbeg, const char* __gend, + const char* __gbeg, size_t __gsize, const _CharT* __first, const _CharT* __last); // This template permits specializing facet output code for @@ -1602,11 +1589,12 @@ namespace std struct __numpunct_cache : public locale::facet { const char* _M_grouping; + size_t _M_grouping_size; bool _M_use_grouping; const _CharT* _M_truename; + size_t _M_truename_size; const _CharT* _M_falsename; - size_t _M_truename_len; - size_t _M_falsename_len; + size_t _M_falsename_size; _CharT _M_decimal_point; _CharT _M_thousands_sep; @@ -1625,10 +1613,10 @@ namespace std bool _M_allocated; __numpunct_cache(size_t __refs = 0) : facet(__refs), - _M_grouping(NULL), _M_use_grouping(false), _M_truename(NULL), - _M_falsename(NULL), _M_truename_len(0), _M_falsename_len(0), - _M_decimal_point(_CharT()), _M_thousands_sep(_CharT()), - _M_allocated(false) + _M_grouping(NULL), _M_grouping_size(0), _M_use_grouping(false), + _M_truename(NULL), _M_truename_size(0), _M_falsename(NULL), + _M_falsename_size(0), _M_decimal_point(_CharT()), + _M_thousands_sep(_CharT()), _M_allocated(false) { } ~__numpunct_cache(); @@ -1645,21 +1633,20 @@ namespace std const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); - const string::size_type __len = __np.grouping().size(); - char* __grouping = new char[__len + 1]; - __np.grouping().copy(__grouping, __len); - __grouping[__len] = char(); + _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 = __len && __np.grouping()[0] != 0; + _M_use_grouping = _M_grouping_size && __np.grouping()[0] != 0; - _M_truename_len = __np.truename().size(); - _CharT* __truename = new _CharT[_M_truename_len]; - __np.truename().copy(__truename, _M_truename_len); + _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_len = __np.falsename().size(); - _CharT* __falsename = new _CharT[_M_falsename_len]; - __np.falsename().copy(__falsename, _M_falsename_len); + _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(); @@ -2421,9 +2408,9 @@ namespace std char __mod, _ValueT __v) const; void - _M_group_float(const string& __grouping, char_type __sep, - const char_type* __p, char_type* __new, char_type* __cs, - int& __len) const; + _M_group_float(const char* __grouping, size_t __grouping_size, + char_type __sep, const char_type* __p, char_type* __new, + char_type* __cs, int& __len) const; template<typename _ValueT> iter_type @@ -2431,9 +2418,9 @@ namespace std _ValueT __v) const; void - _M_group_int(const string& __grouping, char_type __sep, - ios_base& __io, char_type* __new, char_type* __cs, - int& __len) const; + _M_group_int(const char* __grouping, size_t __grouping_size, + char_type __sep, ios_base& __io, char_type* __new, + char_type* __cs, int& __len) const; void _M_pad(char_type __fill, streamsize __w, ios_base& __io, diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index d781503..4dc3bb4 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -150,6 +150,18 @@ namespace std } }; + // Used by both numeric and monetary facets. + // Check to make sure that the __grouping_tmp string constructed in + // money_get or num_get matches the canonical grouping for a given + // locale. + // __grouping_tmp is parsed L to R + // 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 + __verify_grouping(const char* __grouping, size_t __grouping_size, + const string& __grouping_tmp); + template<typename _CharT, typename _InIter> _InIter num_get<_CharT, _InIter>:: @@ -293,8 +305,8 @@ namespace std if (!__found_dec) __found_grouping += static_cast<char>(__sep_pos); - const string __grouping = __lc->_M_grouping; - if (!std::__verify_grouping(__grouping, __found_grouping)) + if (!std::__verify_grouping(__lc->_M_grouping, __lc->_M_grouping_size, + __found_grouping)) __err |= ios_base::failbit; } @@ -485,8 +497,8 @@ namespace std // Add the ending grouping. __found_grouping += static_cast<char>(__sep_pos); - const string __grouping = __lc->_M_grouping; - if (!std::__verify_grouping(__grouping, __found_grouping)) + if (!std::__verify_grouping(__lc->_M_grouping, __lc->_M_grouping_size, + __found_grouping)) __err |= ios_base::failbit; } @@ -536,13 +548,13 @@ namespace std for (__n = 0; __beg != __end; ++__n, ++__beg) { if (__testf) - if (__n < __lc->_M_falsename_len) + if (__n < __lc->_M_falsename_size) __testf = __traits_type::eq(*__beg, __lc->_M_falsename[__n]); else break; if (__testt) - if (__n < __lc->_M_truename_len) + if (__n < __lc->_M_truename_size) __testt = __traits_type::eq(*__beg, __lc->_M_truename[__n]); else break; @@ -550,9 +562,9 @@ namespace std if (!__testf && !__testt) break; } - if (__testf && __n == __lc->_M_falsename_len) + if (__testf && __n == __lc->_M_falsename_size) __v = 0; - else if (__testt && __n == __lc->_M_truename_len) + else if (__testt && __n == __lc->_M_truename_size) __v = 1; else __err |= ios_base::failbit; @@ -793,8 +805,8 @@ namespace std template<typename _CharT, typename _OutIter> void num_put<_CharT, _OutIter>:: - _M_group_int(const string& __grouping, _CharT __sep, ios_base& __io, - _CharT* __new, _CharT* __cs, int& __len) const + _M_group_int(const char* __grouping, size_t __grouping_size, _CharT __sep, + ios_base& __io, _CharT* __new, _CharT* __cs, int& __len) const { // By itself __add_grouping cannot deal correctly with __cs when // ios::showbase is set and ios_base::oct || ios_base::hex. @@ -817,9 +829,9 @@ namespace std __new[1] = __cs[1]; } _CharT* __p; - __p = std::__add_grouping(__new + __off, __sep, __grouping.data(), - __grouping.data() + __grouping.size(), - __cs + __off, __cs + __len); + __p = std::__add_grouping(__new + __off, __sep, __grouping, + __grouping_size, __cs + __off, + __cs + __len); __len = __p - __new; } @@ -854,8 +866,8 @@ namespace std // number of digits, but no more. _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len * 2)); - _M_group_int(__lc->_M_grouping, __lc->_M_thousands_sep, __io, - __cs2, __cs, __len); + _M_group_int(__lc->_M_grouping, __lc->_M_grouping_size, + __lc->_M_thousands_sep, __io, __cs2, __cs, __len); __cs = __cs2; } @@ -878,16 +890,15 @@ namespace std template<typename _CharT, typename _OutIter> void num_put<_CharT, _OutIter>:: - _M_group_float(const string& __grouping, _CharT __sep, const _CharT* __p, - _CharT* __new, _CharT* __cs, int& __len) const + _M_group_float(const char* __grouping, size_t __grouping_size, _CharT __sep, + const _CharT* __p, _CharT* __new, _CharT* __cs, int& __len) const { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 282. What types does numpunct grouping refer to? // Add grouping, if necessary. _CharT* __p2; const int __declen = __p ? __p - __cs : __len; - __p2 = std::__add_grouping(__new, __sep, __grouping.data(), - __grouping.data() + __grouping.size(), + __p2 = std::__add_grouping(__new, __sep, __grouping, __grouping_size, __cs, __cs + __declen); // Tack on decimal part. @@ -1003,8 +1014,8 @@ namespace std // number of digits, but no more. _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len * 2)); - _M_group_float(__lc->_M_grouping, __lc->_M_thousands_sep, __p, - __ws2, __ws, __len); + _M_group_float(__lc->_M_grouping, __lc->_M_grouping_size, + __lc->_M_thousands_sep, __p, __ws2, __ws, __len); __ws = __ws2; } @@ -1044,8 +1055,8 @@ namespace std const _CharT* __name = __v ? __lc->_M_truename : __lc->_M_falsename; - int __len = __v ? __lc->_M_truename_len - : __lc->_M_falsename_len; + int __len = __v ? __lc->_M_truename_size + : __lc->_M_falsename_size; const streamsize __w = __io.width(); if (__w > static_cast<streamsize>(__len)) @@ -1308,7 +1319,9 @@ namespace std // Test for grouping fidelity. if (__grouping.size() && __grouping_tmp.size()) { - if (!std::__verify_grouping(__grouping, __grouping_tmp)) + if (!std::__verify_grouping(__grouping.data(), + __grouping.size(), + __grouping_tmp)) __testvalid = false; } @@ -1461,12 +1474,12 @@ namespace std const char_type __sep = __intl ? __mpt.thousands_sep() : __mpf.thousands_sep(); const char* __gbeg = __grouping.data(); - const char* __gend = __gbeg + __grouping.size(); + const size_t __glen = __grouping.size(); const int __n = (__end - __beg) * 2; _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __n)); _CharT* __ws_end = std::__add_grouping(__ws2, __sep, __gbeg, - __gend, __beg, __end); + __glen, __beg, __end); __value.insert(0, __ws2, __ws_end - __ws2); } else @@ -2268,13 +2281,12 @@ namespace std __oldlen - __mod); } - template<typename _CharT> - bool - __verify_grouping(const basic_string<_CharT>& __grouping, - const basic_string<_CharT>& __grouping_tmp) + 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, __grouping.size() - 1); + const size_t __min = std::min(__n, __grouping_size - 1); size_t __i = __n; bool __test = true; @@ -2293,15 +2305,16 @@ namespace std template<typename _CharT> _CharT* - __add_grouping(_CharT* __s, _CharT __sep, - const char* __gbeg, const char* __gend, + __add_grouping(_CharT* __s, _CharT __sep, + const char* __gbeg, size_t __gsize, const _CharT* __first, const _CharT* __last) { if (__last - __first > *__gbeg) { - const bool __bump = __gbeg + 1 != __gend; + const bool __bump = __gsize != 1; __s = std::__add_grouping(__s, __sep, __gbeg + __bump, - __gend, __first, __last - *__gbeg); + __gsize - __bump, __first, + __last - *__gbeg); __first = __last - *__gbeg; *__s++ = __sep; } diff --git a/libstdc++-v3/src/locale-inst.cc b/libstdc++-v3/src/locale-inst.cc index 7a41ef8..25c3018 100644 --- a/libstdc++-v3/src/locale-inst.cc +++ b/libstdc++-v3/src/locale-inst.cc @@ -272,14 +272,9 @@ namespace std // locale functions. template C* - __add_grouping<C>(C*, C, char const*, char const*, + __add_grouping<C>(C*, C, char const*, size_t, C const*, C const*); - template - bool - __verify_grouping<C>(const basic_string<C>&, - const basic_string<C>&); - template class __pad<C, char_traits<C> >; template |