From 631ba05e3d33fb90590a7e47e0d7f613a1538202 Mon Sep 17 00:00:00 2001 From: David Seymour Date: Fri, 11 Jan 2002 05:07:22 +0000 Subject: [PATCH] locale_facets.h (num_get<>): Return advanced iterator for _M_extract_float and _M_extract_int 2002-01-10 David Seymour * include/bits/locale_facets.h (num_get<>): Return advanced iterator for _M_extract_float and _M_extract_int * include/bits/locale_facets.tcc (num_get<>::_M_extract_float) (num_get<>::_M_extract_int): Likewise, all callers changed * testsuite/22_locale/num_get_members_char.cc: Testcase From-SVN: r48764 --- libstdc++-v3/ChangeLog | 8 +++ libstdc++-v3/include/bits/locale_facets.h | 4 +- libstdc++-v3/include/bits/locale_facets.tcc | 49 +++++++++++-------- .../22_locale/num_get_members_char.cc | 31 +++++++++++- 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 994029d7f24..c2c6993a0be 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2002-01-10 David Seymour + + * include/bits/locale_facets.h (num_get<>): Return advanced iterator + for _M_extract_float and _M_extract_int + * include/bits/locale_facets.tcc (num_get<>::_M_extract_float) + (num_get<>::_M_extract_int): Likewise, all callers changed + * testsuite/22_locale/num_get_members_char.cc: Testcase + 2002-01-09 Paolo Carlini * libsupc++/exception (bad_exception): Add comment. diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index 824b03a18ca..7fad2e0e8fa 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -641,11 +641,11 @@ namespace std protected: virtual ~num_get() { } - void + iter_type _M_extract_float(iter_type, iter_type, ios_base&, ios_base::iostate&, string& __xtrc) const; - void + iter_type _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&, char* __xtrc, int __max, int& __base) const; diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 2731640029f..6e0e8b9f1bc 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -88,7 +88,7 @@ namespace std template - void + _InIter num_get<_CharT, _InIter>:: _M_extract_float(_InIter __beg, _InIter __end, ios_base& __io, ios_base::iostate& __err, string& __xtrc) const @@ -213,10 +213,11 @@ namespace std __xtrc += char(); if (__beg == __end) __err |= ios_base::eofbit; + return __beg; } template - void + _InIter num_get<_CharT, _InIter>:: _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io, ios_base::iostate& __err, char* __xtrc, int __max, @@ -369,6 +370,7 @@ namespace std __xtrc[__pos] = char(); if (__beg == __end) __err |= ios_base::eofbit; + return __beg; } #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS @@ -394,8 +396,8 @@ namespace std // that can be represented without change" so we have to add 1 to it // in order to obtain the max number of digits. The same for the // other do_get for integral types below. - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, __base); // Stage 2: convert and store results. char* __sanity; @@ -459,8 +461,8 @@ namespace std // integral types. char __xtrc[32]; int __base; - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, __base); // Stage 2: convert and store results. char* __sanity; @@ -485,8 +487,9 @@ namespace std // integral types. char __xtrc[32]; int __base; - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, + __base); // Stage 2: convert and store results. char* __sanity; @@ -512,8 +515,9 @@ namespace std // integral types. char __xtrc[32]; int __base; - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, + __base); // Stage 2: convert and store results. char* __sanity; @@ -539,8 +543,9 @@ namespace std // integral types. char __xtrc[32]; int __base; - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, + __base); // Stage 2: convert and store results. char* __sanity; @@ -566,8 +571,8 @@ namespace std // integral types. char __xtrc[32]; int __base; - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, __base); // Stage 2: convert and store results. char* __sanity; @@ -592,8 +597,9 @@ namespace std // integral types. char __xtrc[32]; int __base; - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, + __base); // Stage 2: convert and store results. char* __sanity; @@ -617,7 +623,7 @@ namespace std // Stage 1: extract and determine the conversion specifier. string __xtrc; __xtrc.reserve(32); - _M_extract_float(__beg, __end, __io, __err, __xtrc); + __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc); // Stage 2: convert and store results. char* __sanity; @@ -644,7 +650,7 @@ namespace std // Stage 1: extract and determine the conversion specifier. string __xtrc; __xtrc.reserve(32); - _M_extract_float(__beg, __end, __io, __err, __xtrc); + __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc); // Stage 2: convert and store results. char* __sanity; @@ -667,7 +673,7 @@ namespace std // Stage 1: extract and determine the conversion specifier. string __xtrc; __xtrc.reserve(32); - _M_extract_float(__beg, __end, __io, __err, __xtrc); + __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc); #if defined(_GLIBCPP_USE_C99) && !defined(__hpux) // Stage 2: convert and store results. @@ -721,8 +727,9 @@ namespace std // integral types. char __xtrc[32]; int __base; - _M_extract_int(__beg, __end, __io, __err, __xtrc, - numeric_limits::digits10 + 1, __base); + __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, + numeric_limits::digits10 + 1, + __base); // Stage 2: convert and store results. char* __sanity; diff --git a/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc b/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc index 3ab623645fc..68313437f7f 100644 --- a/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc +++ b/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc @@ -1,6 +1,6 @@ // 2001-11-21 Benjamin Kosnik -// Copyright (C) 2001 Free Software Foundation +// Copyright (C) 2001-2002 Free Software Foundation // // 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 @@ -235,10 +235,39 @@ void test01() #endif } +// 2002-01-10 David Seymour +void test02() +{ + using namespace std; + bool test = true; + + // Num_get works with other iterators besides streambuf output iterators + typedef string::const_iterator iter_type; + typedef num_get num_get_type; + const ios_base::iostate goodbit = ios_base::goodbit; + const ios_base::iostate eofbit = ios_base::eofbit; + ios_base::iostate err = ios_base::goodbit; + const locale loc_c = locale::classic(); + + long i = 0; + const string str = "20000106 Elizabeth Durack"; + istringstream iss; // need an ios, add my num_get facet + iss.imbue(locale(loc_c, new num_get_type)); + + // Iterator advanced, state, output. + const num_get_type& ng = use_facet(iss.getloc()); + iter_type end = ng.get(str.begin(), str.end(), iss, err, i); + string rem(end, str.end()); + + VERIFY( err == goodbit ); + VERIFY( i == 20000106); + VERIFY( rem == " Elizabeth Durack" ); +} int main() { test01(); + test02(); return 0; }