hi to all, I'm trying to implementing a string class as a std::list of elements that can be common char, wchar_t or something else (as utf-16 chars, for example). In order to obtain this, I've defined a collection as a template class, and used with different value_type(s). When I try to use the collection with char or wchar_t, the boost algo to_upper works fine but, when I use the collection template with a UTF16::Char (a class that implements the UTF-16 encoding) I obtain the following exception: Exception catch:St8bad_cast The following code is the definition of the Char class and an example of its use with the standard list and the boost algo: namespace UTF16 { class Char { public: Char(); Char(const char c); // UTF-16 encoding constructor Char(wchar_t v); bool operator == (const Char& c) const; bool operator != (const Char& c) const; operator wchar_t () const; Char(const Char& chr); Char(Char& chr); ~Char(); Char& operator = (const Char& chr); Char& operator = (Char& chr); private: u_int16_t* _value; size_t _size; }; } int main(int argc, char *argv[]) { try { listUTF16::Char l; l.push_back(UTF16::Char('a')); // THE FOLLOWING LINE PRODUCES A 'bad_cast' exception... boost::algorithm::to_upper(l); } catch(const exception& error) { cout << "Exception catch:" << error.what() << endl; } catch(...) { cerr << "Unhandled exception.\n"; } return EXIT_SUCCESS; } Is there something wrong/missing in the definition of the Char class? Or maybe the boost string algos are usable only with char and wchar_t? Thanks in advance Giampiero.
Hi, to_upper algorithm is using locales to perform the conversion. By defualt, default locales are used. AFAIK locales in the standar library support only char and wchar_t data types. So you need to provide your own conversion facet to the locales (the one, that will work with UTF16:Char) and provide this locales as a parameter to the to_upper algorithm. (or you can modify the default locales). Unless so you do so, to_upper will not be able to work with your string class. Best Regards, Pavol. On Tue, Aug 09, 2005 at 06:55:00PM +0200, Giampiero Gabbiani wrote:
hi to all, I'm trying to implementing a string class as a std::list of elements that can be common char, wchar_t or something else (as utf-16 chars, for example). In order to obtain this, I've defined a collection as a template class, and used with different value_type(s). When I try to use the collection with char or wchar_t, the boost algo to_upper works fine but, when I use the collection template with a UTF16::Char (a class that implements the UTF-16 encoding) I obtain the following exception:
Exception catch:St8bad_cast
The following code is the definition of the Char class and an example of its use with the standard list and the boost algo:
namespace UTF16 {
class Char { public: Char(); Char(const char c); // UTF-16 encoding constructor Char(wchar_t v); bool operator == (const Char& c) const; bool operator != (const Char& c) const; operator wchar_t () const; Char(const Char& chr); Char(Char& chr); ~Char(); Char& operator = (const Char& chr); Char& operator = (Char& chr); private: u_int16_t* _value; size_t _size; };
}
int main(int argc, char *argv[]) { try { listUTF16::Char l; l.push_back(UTF16::Char('a'));
// THE FOLLOWING LINE PRODUCES A 'bad_cast' exception... boost::algorithm::to_upper(l);
} catch(const exception& error) { cout << "Exception catch:" << error.what() << endl; } catch(...) { cerr << "Unhandled exception.\n"; } return EXIT_SUCCESS; }
Is there something wrong/missing in the definition of the Char class? Or maybe the boost string algos are usable only with char and wchar_t?
Thanks in advance Giampiero.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Giampiero Gabbiani
-
Pavol Droba