This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

codecvt


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;
			}

			...

	};


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]