aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2003-10-24 22:51:15 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2003-10-24 22:51:15 +0000
commit761faeec3146cedf22989e688c8e5d43e23a2c74 (patch)
tree823122ab2d102de228ac9319c5347dd66d069abe
parent7bb1ad9314f7e671cf8c4b69da55dc0afe7cba01 (diff)
downloadgcc-761faeec3146cedf22989e688c8e5d43e23a2c74.zip
gcc-761faeec3146cedf22989e688c8e5d43e23a2c74.tar.gz
gcc-761faeec3146cedf22989e688c8e5d43e23a2c74.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog13
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc24
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get/get/char/11.cc63
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11.cc63
4 files changed, 151 insertions, 12 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 999cadb..2c1ec40 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,18 @@
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):
Prefer '=' to an unnecessary '&='.
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 4804e9b..94d41a5 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -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;
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/11.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/11.cc
new file mode 100644
index 0000000..5494ca0
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/11.cc
@@ -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;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11.cc
new file mode 100644
index 0000000..af2c230
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11.cc
@@ -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;
+}