diff options
author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-06 05:58:10 +0000 |
---|---|---|
committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-06 05:58:10 +0000 |
commit | 6328b3786cbbc4b7c01788b3ebfc8072403c1e1f (patch) | |
tree | a5992ed0d713382e1bf0580bdae524a2878fb8ce /libstdc++-v3 | |
parent | b197fbcf9fff937f22cfe62dfad1a2e48dafb21c (diff) | |
download | gcc-6328b3786cbbc4b7c01788b3ebfc8072403c1e1f.tar.gz |
2003-02-05 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/locale_facets.tcc (time_put::do_put): Use __write.
(money_put::do_put): Same.
2003-02-05 Jerry Quinn <jlquinn@optonline.net>
* include/bits/ios_base.h (ios_base): Document reserved storage.
* include/bits/locale_facets.h: (struct __pad): Comment on
implementation.
(__verify_grouping): Same.
(__add_grouping): Same.
* include/bits/locale_facets.tcc (__verify_grouping): Move
comments to declaration.
(__add_grouping): Same.
* include/bits/locale_facets.tcc:
(__write<_CharT, _OutIter>): New function.
(__write<_CharT>): New function specialization.
(num_put::_M_insert): Remove explicit loop over iterator. Use
__write.
(num_put::_M_widen_float): Remove __basefield.
(num_put::_M_widen_int): Move __basefield to within grouping block.
* include/bits/streambuf_iterator.h: Include <streambuf>.
(ostreambuf_iterator::_M_put): Add.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@62473 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 28 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ios_base.h | 3 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.h | 39 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.tcc | 52 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/streambuf_iterator.h | 34 |
5 files changed, 105 insertions, 51 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 54a9ee888c6..93707882ee9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,31 @@ +2003-02-05 Benjamin Kosnik <bkoz@redhat.com> + + * include/bits/locale_facets.tcc (time_put::do_put): Use __write. + (money_put::do_put): Same. + +2003-02-05 Jerry Quinn <jlquinn@optonline.net> + + * include/bits/ios_base.h (ios_base): Document reserved storage. + + * include/bits/locale_facets.h: (struct __pad): Comment on + implementation. + (__verify_grouping): Same. + (__add_grouping): Same. + * include/bits/locale_facets.tcc (__verify_grouping): Move + comments to declaration. + (__add_grouping): Same. + + * include/bits/locale_facets.tcc: + (__write<_CharT, _OutIter>): New function. + (__write<_CharT>): New function specialization. + (num_put::_M_insert): Remove explicit loop over iterator. Use + __write. + (num_put::_M_widen_float): Remove __basefield. + (num_put::_M_widen_int): Move __basefield to within grouping block. + + * include/bits/streambuf_iterator.h: Include <streambuf>. + (ostreambuf_iterator::_M_put): Add. + 2003-02-05 Paolo Carlini <pcarlini@unitus.it> * testsuite/26_numerics/valarray_name_lookup.cc: Fix typo. diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index bdcb2b6eeda..a7d4bf614c4 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -1,6 +1,6 @@ // Iostreams base classes -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -416,6 +416,7 @@ namespace std _Words _M_word_zero; // Guaranteed storage. + // The first 5 iword and pword slots are reserved for internal use. static const int _S_local_word_size = 8; _Words _M_local_word[_S_local_word_size]; diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index de9cef6d7e4..a2a043c3a8d 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -103,7 +103,8 @@ namespace std __convert_to_v(const char*, long double&, ios_base::iostate&, const __c_locale&, int); - + // NB: __pad is a struct, rather than a function, so it can be + // partially-specialized. template<typename _CharT, typename _Traits> struct __pad { @@ -113,17 +114,53 @@ namespace std const streamsize __oldlen, const bool __num); }; + // 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, 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. template<typename _CharT> _CharT* __add_grouping(_CharT* __s, _CharT __sep, const char* __gbeg, const char* __gend, const _CharT* __first, const _CharT* __last); + // This template permits specializing facet output code for + // ostreambuf_iterator. For ostreambuf_iterator, sputn is + // significantly more efficient than incrementing iterators. + template<typename _CharT> + inline + ostreambuf_iterator<_CharT> + __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len) + { + __s._M_put(__ws, __len); + return __s; + } + + // This is the unspecialized form of the template. + template<typename _CharT, typename _OutIter> + inline + _OutIter + __write(_OutIter __s, const _CharT* __ws, int __len) + { + for (int __j = 0; __j < __len; __j++, ++__s) + *__s = __ws[__j]; + return __s; + } + // 22.2.1.1 Template class ctype // Include host and configuration specific ctype enums for ctype_base. #include <bits/ctype_base.h> diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index c5263a1ed5a..e6e9fbe8697 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -750,7 +750,6 @@ namespace std //282. What types does numpunct grouping refer to? // Add grouping, if necessary. const string __grouping = __np.grouping(); - ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield; if (__grouping.size()) { _CharT* __p2; @@ -797,7 +796,6 @@ namespace std // Add grouping, if necessary. const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); const string __grouping = __np.grouping(); - const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield; if (__grouping.size()) { // By itself __add_grouping cannot deal correctly with __ws when @@ -806,6 +804,8 @@ namespace std // However, remember that the latter do not occur if the number // printed is '0' (__len == 1). streamsize __off = 0; + const ios_base::fmtflags __basefield = __io.flags() + & ios_base::basefield; if ((__io.flags() & ios_base::showbase) && __len > 1) if (__basefield == ios_base::oct) { @@ -840,6 +840,7 @@ namespace std { typedef char_traits<_CharT> __traits_type; // [22.2.2.2.2] Stage 3. + // If necessary, pad. streamsize __w = __io.width(); _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); @@ -855,9 +856,7 @@ namespace std // [22.2.2.2.2] Stage 4. // Write resulting, fully-formatted string to output iterator. - for (int __j = 0; __j < __len; ++__j, ++__s) - *__s = __ws[__j]; - return __s; + return __write(__s, __ws, __len); } template<typename _CharT, typename _OutIter> @@ -1196,7 +1195,8 @@ namespace std char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); int __len = __convert_from_v(__cs, 0, "%.01Lf", __units, _S_c_locale); #endif - _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __cs_size)); + _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __cs_size)); __ctype.widen(__cs, __cs + __len, __ws); string_type __digits(__ws); return this->do_put(__s, __intl, __io, __fill, __digits); @@ -1290,7 +1290,7 @@ namespace std const char* __gend = __gbeg + __grouping.size(); const int __n = (__end - __beg) * 2; _CharT* __ws2 = - static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __n)); + static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __n)); _CharT* __ws_end = __add_grouping(__ws2, __sep, __gbeg, __gend, __beg, __end); __value.insert(0, __ws2, __ws_end - __ws2); @@ -1359,8 +1359,7 @@ namespace std } // Write resulting, fully-formatted string to output iterator. - for (size_type __j = 0; __j < __len; ++__j, ++__s) - *__s = __res[__j]; + __s = __write(__s, __res.c_str(), __len); } __io.width(0); return __s; @@ -1616,7 +1615,8 @@ namespace std ios_base::iostate& __err) const { typedef char_traits<_CharT> __traits_type; - int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int) * __indexlen)); + int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int) + * __indexlen)); size_t __nmatches = 0; size_t __pos = 0; bool __testvalid = true; @@ -1633,8 +1633,8 @@ namespace std // Find smallest matching string. size_t __minlen = 10; for (size_t __i2 = 0; __i2 < __nmatches; ++__i2) - __minlen = std::min(__minlen, - __traits_type::length(__names[__matches[__i2]])); + __minlen = min(__minlen, + __traits_type::length(__names[__matches[__i2]])); if (__pos < __minlen && __beg != __end) { @@ -1878,8 +1878,7 @@ namespace std // NB: This size is arbitrary. Should this be a data member, // initialized at construction? const size_t __maxlen = 64; - char_type* __res = - static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen)); + char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen)); // NB: In IEE 1003.1-200x, and perhaps other locale models, it // is possible that the format character will be longer than one @@ -1903,10 +1902,7 @@ namespace std __tp._M_put(__res, __maxlen, __fmt, __tm); // Write resulting, fully-formatted string to output iterator. - size_t __len = char_traits<char_type>::length(__res); - for (size_t __i = 0; __i < __len; ++__i, ++__s) - *__s = __res[__i]; - return __s; + return __write(__s, __res, char_traits<char_type>::length(__res)); } @@ -1946,8 +1942,8 @@ namespace std // If the buffer was not large enough, try again with the correct size. if (__res >= __len) { - __c = - static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__res + 1))); + __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * (__res + 1))); _M_transform(__c, __lo, __res + 1); } return string_type(__c); @@ -1984,7 +1980,8 @@ namespace std const streamsize __oldlen, const bool __num) { size_t __plen = static_cast<size_t>(__newlen - __oldlen); - _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __plen)); + _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __plen)); _Traits::assign(__pads, __plen, __fill); _CharT* __beg; @@ -2054,14 +2051,6 @@ namespace std __newlen - __beglen - __mod); } - // 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, @@ -2086,11 +2075,6 @@ namespace std return __test; } - // 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. template<typename _CharT> _CharT* __add_grouping(_CharT* __s, _CharT __sep, diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index 152df9c6e4b..c2dee887c4b 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -1,6 +1,6 @@ // Streambuf iterators -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -28,8 +28,6 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// XXX Should specialize copy, find algorithms for streambuf iterators. - /** @file streambuf_iterator.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. @@ -40,6 +38,10 @@ #pragma GCC system_header +#include <streambuf> + +// NB: Should specialize copy, find algorithms for streambuf iterators. + namespace std { // 24.5.3 Template class istreambuf_iterator @@ -166,7 +168,6 @@ namespace std bool _M_failed; public: - inline ostreambuf_iterator(ostream_type& __s) throw () : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { } @@ -174,7 +175,13 @@ namespace std : _M_sbuf(__s), _M_failed(!_M_sbuf) { } ostreambuf_iterator& - operator=(_CharT __c); + operator=(_CharT __c) + { + if (!_M_failed && + _Traits::eq_int_type(_M_sbuf->sputc(__c), _Traits::eof())) + _M_failed = true; + return *this; + } ostreambuf_iterator& operator*() throw() @@ -191,16 +198,13 @@ namespace std bool failed() const throw() { return _M_failed; } - }; - template<typename _CharT, typename _Traits> - inline ostreambuf_iterator<_CharT, _Traits>& - ostreambuf_iterator<_CharT, _Traits>::operator=(_CharT __c) - { - if (!_M_failed && - _Traits::eq_int_type(_M_sbuf->sputc(__c), _Traits::eof())) - _M_failed = true; - return *this; - } + ostreambuf_iterator& + _M_put(const _CharT* __ws, streamsize __len) + { + this->_M_sbuf->sputn(__ws, __len); + return *this; + } + }; } // namespace std #endif |