locale.cc (locale::locale(const char* __name)): Consolidate name setting.

2000-09-15  Benjamin Kosnik  <bkoz@purist.soma.redhat.com>

        * src/locale.cc (locale::locale(const char* __name)): Consolidate
        name setting. Add checks for NULL __name pointers. Remove calls to
        _S_initialize() as initial locale initialization can either be
        assumed, or needs to be made consistent throughout locale
        constructors.
        (locale::locale(const locale& __other, const char* __name,
        category __cat): Add checks for NULL name. Add checks for
        assignment to self.
        * src/localename.cc (locale::_Impl:: _Impl(const _Impl& __other,
        const string& __name, category __cat, size_t __refs)): Set correct
        name, has_name values.
        * testsuite/22_locale/ctor_copy_dtor.cc (test01): More tests.
        * docs/22_locale/locale.html: New file, more unfinished docs...

From-SVN: r36451
This commit is contained in:
Benjamin Kosnik 2000-09-15 22:52:52 +00:00 committed by Benjamin Kosnik
parent 04807c2864
commit d9fbca261e
4 changed files with 61 additions and 10 deletions

View File

@ -1,3 +1,19 @@
2000-09-15 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
* src/locale.cc (locale::locale(const char* __name)): Consolidate
name setting. Add checks for NULL __name pointers. Remove calls to
_S_initialize() as initial locale initialization can either be
assumed, or needs to be made consistent throughout locale
constructors.
(locale::locale(const locale& __other, const char* __name,
category __cat): Add checks for NULL name. Add checks for
assignment to self.
* src/localename.cc (locale::_Impl:: _Impl(const _Impl& __other,
const string& __name, category __cat, size_t __refs)): Set correct
name, has_name values.
* testsuite/22_locale/ctor_copy_dtor.cc (test01): More tests.
* docs/22_locale/locale.html: New file, more unfinished docs...
2000-09-14 Benjamin Kosnik <bkoz@purist.soma.redhat.com> 2000-09-14 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
* src/locale.cc (locale::name()): Implement. * src/locale.cc (locale::name()): Implement.

View File

@ -554,20 +554,32 @@ namespace std {
locale::locale(const char* __name) locale::locale(const char* __name)
{ {
_S_initialize(); if (__name)
{
if (strcmp(__name, "C") == 0 || strcmp(__name, "POSIX") == 0) if (strcmp(__name, "C") == 0 || strcmp(__name, "POSIX") == 0)
(_M_impl = _S_classic)->_M_add_reference(); (_M_impl = _S_classic)->_M_add_reference();
else
{
// Might throw: // Might throw:
else
_M_impl = new _Impl(*_S_classic, __name, all, 1); _M_impl = new _Impl(*_S_classic, __name, all, 1);
_M_impl->_M_has_name = true;
} }
else
throw runtime_error("attempt to create named locale from NULL name");
} }
locale::locale(const locale& __other, const char* __name, category __cat) locale::locale(const locale& __other, const char* __name, category __cat)
: _M_impl(new _Impl(*__other._M_impl, __name, _S_normalize_category(__cat), 1)) {
{ } if (__name)
{
if (__other.name() == __name)
(_M_impl = __other._M_impl)->_M_add_reference();
// Might throw:
else
_M_impl = new _Impl(*__other._M_impl, __name,
_S_normalize_category(__cat), 1);
}
else
throw runtime_error("attempt to create locale from NULL named locale");
}
bool bool
locale::operator==(const locale& __rhs) const throw() locale::operator==(const locale& __rhs) const throw()

View File

@ -92,7 +92,7 @@ namespace std {
: _M_references(__refs - 1) : _M_references(__refs - 1)
// , _M_facets(other._M_facets) // , _M_facets(other._M_facets)
// , _M_category_names(other._M_category_names) // , _M_category_names(other._M_category_names)
, _M_has_name(__other._M_has_name), _M_name(__other._M_name) , _M_has_name(__name != "*"), _M_name(__name)
{ {
#if 1 #if 1
typedef vector<facet*, allocator<facet*> > __vec_facet; typedef vector<facet*, allocator<facet*> > __vec_facet;

View File

@ -63,7 +63,7 @@ void test01()
locale loc07(""); locale loc07("");
VERIFY (loc07 != loc01); VERIFY (loc07 != loc01);
VERIFY (loc07 != loc02); VERIFY (loc07 != loc02);
VERIFY (loc06.name() == ""); VERIFY (loc07.name() == "");
try try
{ locale loc08(static_cast<const char*>(NULL)); } { locale loc08(static_cast<const char*>(NULL)); }
catch(runtime_error& obj) catch(runtime_error& obj)
@ -73,6 +73,29 @@ void test01()
// 4 // 4
// locale(const locale& other, const char* std_name, category) // locale(const locale& other, const char* std_name, category)
locale loc09(loc06, "C", locale::ctype);
VERIFY (loc09.name() == "fr_FR");
VERIFY (loc09 != loc01);
VERIFY (loc09 != loc06);
// XXX somehow check that the ctype, codecvt facets have "C" locale bits...
locale loc10(loc02, "C", locale::ctype);
VERIFY (loc10.name() == "*");
VERIFY (loc10 != loc01); // As not named, even tho facets same...
VERIFY (loc10 != loc02);
// XXX somehow check that the ctype, codecvt facets have "C" locale bits...
locale loc11(loc01, "C", locale::ctype);
VERIFY (loc11.name() == "C");
VERIFY (loc11 == loc01);
// XXX somehow check that the ctype, codecvt facets have "C" locale bits...
try
{ locale loc12(loc01, static_cast<const char*>(NULL), locale::ctype); }
catch(runtime_error& obj)
{ VERIFY (true); }
catch(...)
{ VERIFY (false); }