locale_facets.tcc (money_get::do_get(..., long double&): Properly size the temporary buffer.

2003-10-24  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (money_get::do_get(...,
	long double&): Properly size the temporary buffer.
	* testsuite/22_locale/money_get/get/char/11.cc: New.
	* testsuite/22_locale/money_get/get/wchar_t/11.cc: Ditto.

	* include/bits/locale_facets.tcc (num_put::_M_group_int,
	num_put::_M_group_float, money_put::do_put(..., const
	string_type&), collate::do_compare, collate::do_transform):
	Prefer basic_string::data() to c_str() when the '\0'
	terminator is not really needed.

From-SVN: r72911
This commit is contained in:
Paolo Carlini 2003-10-24 22:51:15 +00:00 committed by Paolo Carlini
parent 7bb1ad9314
commit 761faeec31
4 changed files with 151 additions and 12 deletions

View File

@ -1,3 +1,16 @@
2003-10-24 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (money_get::do_get(...,
long double&): Properly size the temporary buffer.
* testsuite/22_locale/money_get/get/char/11.cc: New.
* testsuite/22_locale/money_get/get/wchar_t/11.cc: Ditto.
* include/bits/locale_facets.tcc (num_put::_M_group_int,
num_put::_M_group_float, money_put::do_put(..., const
string_type&), collate::do_compare, collate::do_transform):
Prefer basic_string::data() to c_str() when the '\0'
terminator is not really needed.
2003-10-24 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (__verify_grouping):

View File

@ -795,8 +795,8 @@ namespace std
__new[1] = __cs[1];
}
_CharT* __p;
__p = std::__add_grouping(__new + __off, __sep, __grouping.c_str(),
__grouping.c_str() + __grouping.size(),
__p = std::__add_grouping(__new + __off, __sep, __grouping.data(),
__grouping.data() + __grouping.size(),
__cs + __off, __cs + __len);
__len = __p - __new;
}
@ -866,8 +866,8 @@ namespace std
// Add grouping, if necessary.
_CharT* __p2;
const int __declen = __p ? __p - __cs : __len;
__p2 = std::__add_grouping(__new, __sep, __grouping.c_str(),
__grouping.c_str() + __grouping.size(),
__p2 = std::__add_grouping(__new, __sep, __grouping.data(),
__grouping.data() + __grouping.size(),
__cs, __cs + __declen);
// Tack on decimal part.
@ -1117,12 +1117,12 @@ namespace std
string_type __str;
__beg = this->do_get(__beg, __end, __intl, __io, __err, __str);
const int __n = numeric_limits<long double>::digits10;
char* __cs = static_cast<char*>(__builtin_alloca(__n));
const int __cs_size = __str.size() + 1;
char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
const locale __loc = __io.getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
const _CharT* __wcs = __str.c_str();
__ctype.narrow(__wcs, __wcs + __str.size() + 1, char(), __cs);
__ctype.narrow(__wcs, __wcs + __cs_size, char(), __cs);
std::__convert_to_v(__cs, __units, __err, _S_get_c_locale());
return __beg;
}
@ -1457,7 +1457,7 @@ namespace std
{
const char_type __sep = __intl ? __mpt.thousands_sep()
: __mpf.thousands_sep();
const char* __gbeg = __grouping.c_str();
const char* __gbeg = __grouping.data();
const char* __gend = __gbeg + __grouping.size();
const int __n = (__end - __beg) * 2;
_CharT* __ws2 =
@ -1530,7 +1530,7 @@ namespace std
}
// Write resulting, fully-formatted string to output iterator.
__s = std::__write(__s, __res.c_str(), __len);
__s = std::__write(__s, __res.data(), __len);
}
__io.width(0);
return __s;
@ -2101,9 +2101,9 @@ namespace std
const string_type __two(__lo2, __hi2);
const _CharT* __p = __one.c_str();
const _CharT* __pend = __one.c_str() + __one.length();
const _CharT* __pend = __one.data() + __one.length();
const _CharT* __q = __two.c_str();
const _CharT* __qend = __two.c_str() + __two.length();
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
@ -2137,7 +2137,7 @@ namespace std
string_type __str(__lo, __hi);
const _CharT* __p = __str.c_str();
const _CharT* __pend = __str.c_str() + __str.length();
const _CharT* __pend = __str.data() + __str.length();
size_t __len = (__hi - __lo) * 2;

View File

@ -0,0 +1,63 @@
// 2003-10-24 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2003 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
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 22.2.6.1.1 money_get members
#include <locale>
#include <sstream>
#include <limits>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
typedef istreambuf_iterator<char> iterator_type;
bool test __attribute__((unused)) = true;
// basic construction
locale loc_de = __gnu_test::try_named_locale("de_DE@euro");
iterator_type end;
istringstream iss;
iss.imbue(loc_de);
// cache the money_get facet
const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc());
// A _very_ big amount.
string str = "1";
for (int i = 0; i < 2 * numeric_limits<long double>::digits10; ++i)
str += ".000";
str += ",00 ";
iss.str(str);
iterator_type is_it01(iss);
long double result1;
ios_base::iostate err01 = ios_base::goodbit;
mon_get.get(is_it01, end, true, iss, err01, result1);
VERIFY( err01 == ios_base::eofbit );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,63 @@
// 2003-10-24 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2003 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
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 22.2.6.1.1 money_get members
#include <locale>
#include <sstream>
#include <limits>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
typedef istreambuf_iterator<wchar_t> iterator_type;
bool test __attribute__((unused)) = true;
// basic construction
locale loc_de = __gnu_test::try_named_locale("de_DE@euro");
iterator_type end;
wistringstream iss;
iss.imbue(loc_de);
// cache the money_get facet
const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc());
// A _very_ big amount.
wstring str = L"1";
for (int i = 0; i < 2 * numeric_limits<long double>::digits10; ++i)
str += L".000";
str += L",00 ";
iss.str(str);
iterator_type is_it01(iss);
long double result1;
ios_base::iostate err01 = ios_base::goodbit;
mon_get.get(is_it01, end, true, iss, err01, result1);
VERIFY( err01 == ios_base::eofbit );
}
int main()
{
test01();
return 0;
}