This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
codecvt
- From: Walter Horsten <walter dot horsten at pandora dot be>
- To: gcc at gnu dot org
- Date: Sat, 17 Apr 2004 11:31:49 +0200
- Subject: codecvt
- Organization: BA NV
Hi all,
I was digging a little deeper in locales and I started reading more on
codecvt. I recently wrote some character conversion classes, and I wanted to
wrap them in a codecvt child-class. "The C++ Programming Language" proposed
to write an uppercase-conversion class as an excercise. This I did, and it
works perfectly for output streams (by overloading "do_out"), but the
iostream system refuses to call my "do_in" method...I think I overloaded the
method correctly though. So, I was wondering if this functionality is under
development, if I'm overlooking something or if I'm doing something
fundamentally wrong :). I left some code at the end of this mail.
Thanks in advance and kind regards,
Walter Horsten
http://www.geex.be
Here's a code snippet:
This is how I use the codecvt object...
locale loc=locale(locale(), new ToUpper<char>);
cout.imbue(loc);
cin.imbue(loc);
cin >> ds; // ToUpper do_in doesn't seem to act...
cout << ds << endl; // ToUpper do_out acts...
This is the gist of how I implemented it...
template< class Ch >
class ToUpper : public codecvt<Ch, Ch, mbstate_t>
{
...
result do_in(state_type& s, const extern_type* from, const extern_type*
from_end, const extern_type*& from_next, intern_type *to, intern_type*
to_end, intern_type*& to_next) const
{
cerr << "do_in" << endl;
... conversion code ...
return ok;
}
result do_out(state_type& s, const intern_type* from, const intern_type*
from_end, const intern_type*& from_next, extern_type *to, extern_type*
to_end, extern_type*& to_next) const
{
cerr << "do_out" << endl;
... conversion code ...
return ok;
}
...
};