typedef _InIter iter_type;
typedef char_traits<_CharT> __traits_type;
+ static locale::id id;
+
explicit
num_get(size_t __refs = 0) : locale::facet(__refs) { }
ios_base::iostate& __err, void*& __v) const
{ return do_get(__in, __end, __io, __err, __v); }
- static locale::id id;
-
protected:
virtual ~num_get() { }
typedef _CharT char_type;
typedef _OutIter iter_type;
+ static locale::id id;
+
explicit
num_put(size_t __refs = 0) : locale::facet(__refs) { }
const void* __v) const
{ return do_put(__s, __f, __fill, __v); }
- static locale::id id;
-
protected:
virtual
~num_put() { };
typedef _CharT char_type;
typedef _InIter iter_type;
+ static locale::id id;
+
explicit
time_get(size_t __refs = 0)
: locale::facet (__refs), _M_daynames(0), _M_monthnames(0) { }
ios_base::iostate& __err, tm* __t) const
{ return do_get_year(__s,__end,__f,__err,__t); }
- static locale::id id;
-
protected:
virtual
~time_get()
typedef _CharT char_type;
typedef _OutIter iter_type;
+ static locale::id id;
+
explicit
time_put(size_t __refs = 0) : locale::facet (__refs) { }
const tm* __tmb, char __format, char __modifier = 0) const
{ return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
- static locale::id id;
-
protected:
virtual
~time_put() { }
};
template<typename _CharT, typename _OutIter>
- class time_put_byname : time_put<_CharT, _OutIter>
+ class time_put_byname : public time_put<_CharT, _OutIter>
{
public:
typedef _CharT char_type;
explicit
time_put_byname(const char*, size_t __refs = 0)
: time_put<_CharT, _OutIter> (__refs) { }
+
protected:
virtual
~time_put_byname() { }
typedef _InIter iter_type;
typedef basic_string<_CharT> string_type;
+ static locale::id id;
+
explicit
money_get(size_t __refs = 0) : locale::facet(__refs) { }
ios_base::iostate& __err, string_type& __digits) const
{ return do_get(__s, __end, __intl, __f, __err, __digits); }
- static locale::id id;
-
protected:
virtual
~money_get() { }
typedef _OutIter iter_type;
typedef basic_string<_CharT> string_type;
+ static locale::id id;
+
explicit
money_put(size_t __refs = 0) : locale::facet(__refs) { }
char_type __fill, const string_type& __digits) const
{ return do_put(__s, __intl, __f, __fill, __digits); }
- static locale::id id;
-
protected:
virtual
~money_put() { }
explicit
moneypunct(size_t __refs = 0) : _Moneypunct<_CharT> (__refs) { }
+
protected:
virtual
~moneypunct() { }
locale::_Impl::
_Impl(const _Impl& __other, const string& __name, category __cat,
size_t __refs)
- : _M_references(__refs - 1)
- // , _M_facets(other._M_facets)
- // , _M_category_names(other._M_category_names)
- , _M_has_name(__name != "*"), _M_name(__name)
+ : _M_references(__refs - 1), _M_has_name(__other._M_name != "*")
{
-#if 1
typedef vector<facet*, allocator<facet*> > __vec_facet;
typedef vector<string, allocator<string> > __vec_string;
+
+ __cat = _S_normalize_category(__cat); // might throw
try {
_M_facets = new __vec_facet(*(__other._M_facets));
}
- catch (...) {
+ catch(...) {
delete _M_facets;
throw;
}
try {
_M_category_names = new __vec_string(*(__other._M_category_names));
}
- catch (...) {
+ catch(...) {
delete _M_category_names;
throw;
}
-#endif
- // XXX Nathan what are you doing here? Is this supposed to be const?
- // static void(_Impl::* const ctors[]) (const char*) =
+
static void(_Impl::* ctors[]) (const char*) =
{
// NB: Order must match the decl order in class locale.
0
};
- _S_initialize();
- std::vector<facet*>::iterator __it = _M_facets->begin();
+ __vec_facet::iterator __it = _M_facets->begin();
for (; __it != _M_facets->end(); ++__it)
(*__it)->_M_add_reference();
- try {
- category __ccategory = _S_normalize_category(__cat); // might throw
- _M_normalize_category_names(__name, __ccategory);
-
- unsigned mask = (locale::all & -(unsigned)locale::all);
- for (unsigned ix = 0; (-mask & __cat) != 0; ++ix, (mask <<= 1))
- {
- if (!(mask & __cat))
- continue;
-
- if (mask & __ccategory)
- _M_replace_category(_S_classic, _S_facet_categories[ix]);
- else
- (this->*ctors[ix]) (__name.c_str());
- }
- }
- catch (...) {
- __it = _M_facets->begin();
- for (; __it != _M_facets->end(); ++__it)
- (*__it)->_M_remove_reference();
- throw;
- }
+ try
+ {
+ unsigned mask = (locale::all & -(unsigned)locale::all);
+ for (unsigned ix = 0; (-mask & __cat) != 0; ++ix, (mask <<= 1))
+ {
+ if (!(mask & __cat))
+ continue;
+
+ if (mask & __cat)
+ _M_replace_category(_S_classic, _S_facet_categories[ix]);
+ else
+ (this->*ctors[ix])(__name.c_str());
+ }
+ }
+ catch(...)
+ {
+ __it = _M_facets->begin();
+ for (; __it != _M_facets->end(); ++__it)
+ (*__it)->_M_remove_reference();
+ throw;
+ }
+
+ // XXX May need to be adjusted
+ if (__cat == all)
+ _M_name = __name;
}
void
__fpr = __fp;
}
- locale::category
- locale::_Impl::_M_normalize_category_names(const string&,
- locale::category __cat)
- {
- // The problem to be solved here is that locale names
- // generally have one of two forms: they might have
- // only one component, such as "en_US"; or they might
- // have six, such as "en_US fr_FR en_US C C C", where
- // each component names a category. Each vendor has
- // a different order of categories. Each vendor uses
- // a different format:
- // AIX uses "C C C C C C"
- // Sun uses "/C/C/C/C/C/C"
- // HP uses "/0:C;1:C;2:C;3:C;4:C;5:C;6:C;/"
- // (where the 0th element is for LC_ALL.)
- // Most systems (except AIX) permit the long form only for
- // setlocale(LC_ALL,...), and require the short form for
- // other calls. All this matters because locale names are
- // supposed to be compatible between locale("") and
- // setlocale(..., "") constructors.
-
- return __cat;
-#if 0 /* XXX not done */
- unsigned mask = (locale::all & -(unsigned)locale::all);
- for (unsigned ix = 0; (-mask & __cat) != 0; ++ix, (mask <<= 1))
- {
-
- }
-#endif
- }
-
void
- locale::_Impl::_M_construct_collate(const char* /*__name*/)
+ locale::_Impl::_M_construct_collate(const char* __name)
{
-#if 0
- _M_facet_init(new std::collate_byname<char>(__name));
- _M_facet_init(new std::collate_byname<wchar_t>(__name));
-#endif
+ _M_facet_init(new collate_byname<char>(__name, 0));
+ _M_facet_init(new collate_byname<wchar_t>(__name, 0));
}
void
- locale::_Impl::_M_construct_ctype(const char* /*__name*/)
+ locale::_Impl::_M_construct_ctype(const char* __name)
{
-#if 0
- _M_facet_init(new std::ctype_byname<char>(__name));
- _M_facet_init(new std::ctype_byname<wchar_t>(__name));
- _M_facet_init(new std::codecvt_byname<char, char, mbstate_t>(__name));
- _M_facet_init(new std::codecvt_byname<wchar_t, char, mbstate_t>(__name));
-#endif
+ _M_facet_init(new ctype_byname<char>(__name, 0));
+ _M_facet_init(new ctype_byname<wchar_t>(__name, 0));
+ _M_facet_init(new codecvt_byname<char, char, mbstate_t>(__name));
+ _M_facet_init(new codecvt_byname<wchar_t, char, mbstate_t>(__name));
}
void
- locale::_Impl::_M_construct_monetary(const char* /*__name*/)
+ locale::_Impl::_M_construct_monetary(const char* __name)
{
-#if 0
- _M_facet_init(new std::moneypunct_byname<char, false>(__name));
- _M_facet_init(new std::moneypunct_byname<wchar_t, false>(__name));
- _M_facet_init(new std::moneypunct_byname<char, true >(__name));
- _M_facet_init(new std::moneypunct_byname<wchar_t, true >(__name));
+ _M_facet_init(new moneypunct_byname<char, false>(__name, 0));
+ _M_facet_init(new moneypunct_byname<wchar_t, false>(__name, 0));
+ _M_facet_init(new moneypunct_byname<char, true >(__name, 0));
+ _M_facet_init(new moneypunct_byname<wchar_t, true >(__name, 0));
- locale::_M_initialize();
- _M_replace_facet(locale::_S_classic, &std::money_get<char>(__name)::id);
- _M_replace_facet(locale::_S_classic, &std::money_get<wchar_t>(__name)::id);
- _M_replace_facet(locale::_S_classic, &std::money_put<char>(__name)::id);
- _M_replace_facet(locale::_S_classic, &std::money_put<wchar_t>(__name)::id);
-#endif
+ _M_replace_facet(locale::_S_classic, &money_get<char>::id);
+ _M_replace_facet(locale::_S_classic, &money_get<wchar_t>::id);
+ _M_replace_facet(locale::_S_classic, &money_put<char>::id);
+ _M_replace_facet(locale::_S_classic, &money_put<wchar_t>::id);
}
void
- locale::_Impl::_M_construct_numeric(const char* /*__name*/)
+ locale::_Impl::_M_construct_numeric(const char* __name)
{
-#if 0
- _M_facet_init(new std::numpunct_byname<char>(__name));
- _M_facet_init(new std::numpunct_byname<wchar_t>(__name));
+ _M_facet_init(new numpunct_byname<char>(__name, 0));
+ _M_facet_init(new numpunct_byname<wchar_t>(__name, 0));
- locale::_M_initialize();
- _M_replace_facet(locale::_S_classic, &std::num_get<char>::id);
- _M_replace_facet(locale::_S_classic, &std::num_get<wchar_t>::id);
- _M_replace_facet(locale::_S_classic, &std::num_put<char>::id);
- _M_replace_facet(locale::_S_classic, &std::num_put<wchar_t>::id);
-#endif
+ _M_replace_facet(locale::_S_classic, &num_get<char>::id);
+ _M_replace_facet(locale::_S_classic, &num_get<wchar_t>::id);
+ _M_replace_facet(locale::_S_classic, &num_put<char>::id);
+ _M_replace_facet(locale::_S_classic, &num_put<wchar_t>::id);
}
void
- locale::_Impl::_M_construct_time(const char* /*__name*/)
+ locale::_Impl::_M_construct_time(const char* __name)
{
-#if 0
- _M_facet_init(new std::time_get_byname<char>(__name));
- _M_facet_init(new std::time_get_byname<wchar_t>(__name));
- _M_facet_init(new std::time_put_byname<char>(__name));
- _M_facet_init(new std::time_put_byname<wchar_t>(__name));
-#endif
+ _M_facet_init(new time_get_byname<char>(__name, 0));
+ _M_facet_init(new time_get_byname<wchar_t>(__name, 0));
+ _M_facet_init(new time_put_byname<char>(__name, 0));
+ _M_facet_init(new time_put_byname<wchar_t>(__name, 0));
}
void
- locale::_Impl::_M_construct_messages(const char* /*__name*/)
+ locale::_Impl::_M_construct_messages(const char* __name)
{
-#if 0
- _M_facet_init(new std::messages_byname<char>(__name));
- _M_facet_init(new std::messages_byname<wchar_t>(__name));
-#endif
+ _M_facet_init(new messages_byname<char>(__name, 0));
+ _M_facet_init(new messages_byname<wchar_t>(__name, 0));
}
}
#include <stdexcept>
#include <debug_assert.h>
-typedef std::codecvt<char, char, mbstate_t> ccodecvt;
-class gnu_codecvt: public ccodecvt { };
+typedef std::codecvt<char, char, mbstate_t> c_codecvt;
+typedef std::codecvt_byname<char, char, mbstate_t> c_codecvt_byname;
+typedef std::codecvt<wchar_t, char, mbstate_t> w_codecvt;
+typedef std::codecvt_byname<wchar_t, char, mbstate_t> w_codecvt_byname;
+
+class gnu_codecvt: public c_codecvt { };
void test01()
{
using namespace std;
+ typedef unsigned short unicode_t;
+ typedef unicode_t int_type;
+ typedef char ext_type;
+ typedef __enc_traits enc_type;
+ typedef codecvt<int_type, ext_type, enc_type> unicode_codecvt;
+
bool test = true;
string str1, str2;
locale loc02(locale::classic(), new gnu_codecvt);
VERIFY (loc01 != loc02);
VERIFY (loc02.name() == "*");
+ try
+ {
+ VERIFY (has_facet<gnu_codecvt>(loc02));
+ VERIFY (has_facet<c_codecvt>(loc02));
+ VERIFY (has_facet<w_codecvt>(loc02));
+ }
+ catch(...)
+ { VERIFY( false ); }
+
+ try
+ { VERIFY (has_facet<c_codecvt_byname>(loc02)); }
+ catch(bad_cast& obj)
+ { VERIFY( true ); }
+ catch(...)
+ { VERIFY( false ); }
+
+ try
+ { VERIFY (has_facet<w_codecvt_byname>(loc02)); }
+ catch(bad_cast& obj)
+ { VERIFY( true ); }
+ catch(...)
+ { VERIFY( false ); }
+
+ // unicode_codecvt
+ locale loc13(locale::classic(), new unicode_codecvt);
+ VERIFY (loc01 != loc13);
+ VERIFY (loc13.name() == "*");
+ try
+ {
+ VERIFY (has_facet<c_codecvt>(loc13));
+ VERIFY (has_facet<w_codecvt>(loc13));
+ VERIFY (has_facet<unicode_codecvt>(loc13));
+ }
+ catch(...)
+ { VERIFY( false ); }
+
+ try
+ { VERIFY (has_facet<c_codecvt_byname>(loc13)); }
+ catch(bad_cast& obj)
+ { VERIFY( true ); }
+ catch(...)
+ { VERIFY( false ); }
+
+ try
+ { VERIFY (has_facet<w_codecvt_byname>(loc13)); }
+ catch(bad_cast& obj)
+ { VERIFY( true ); }
+ catch(...)
+ { VERIFY( false ); }
// 2
// locale() throw()
// 4
// locale(const locale& other, const char* std_name, category)
locale loc09(loc06, "C", locale::ctype);
- VERIFY (loc09.name() == "fr_FR");
+ VERIFY (loc09.name() != "fr_FR");
+ VERIFY (loc09.name() != "C");
VERIFY (loc09 != loc01);
VERIFY (loc09 != loc06);
// XXX somehow check that the ctype, codecvt facets have "C" locale bits...
{ VERIFY (false); }
-
}
int main ()