Re: help using Glib::ustring



On Wed, 2007-12-19 at 18:54 -0500, Jamiil Abduqadir wrote:
> I am porting my old code to Gtkmm, I have started with the most
> fundamental of applications, a string manipulation class.
> What I am trying to do is very simple, but the new paradigm has me a
> bit confused, to convert a string to upper case here is my code 
> 
> const Glib::ustring& jme::strtools::toUpper( const Glib::ustring& s )
> {
>     //global variable
>     tmp.clear();
>     tmp = s;
>     //remove non-printable characters
>     tmp = this->trimIt( tmp ); 
>     //Iterate through the string until the end of the is found 
>     for ( Glib::ustring::iterator i = tmp.begin(); i != tmp.end();
> ++i ) {
>         *i = toupper( i ); <<=== the old version
>     }
>     return tmp; 
> }
> i = i.uppercase()  ?? did not work
> any suggestions?

UTF-8 is a multibyte representation of unicode.  You cannot write to a
Glib::ustring::interator because the size of the new character (in
multibyte representation) may be different from the size of the existing
one.  That is the reason behind the behaviour, but the way it is
enforced is by having Glib::ustring_Iterator<T>::operator*() return a
new object and not a reference.  In fact, it returns a gunichar object
(a wide character) and not its internal representation (narrow
characters).

See also
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1ustring__Iterator.html#_details

Chris




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]