RE: Glib::ustring



On Thu, 2008-03-06 at 11:01 -0600, Jorge Luis Vidales Valladares wrote:
> Thanks for the int
> 
> I Look for the doc's and finally i came up with this that works
>   
>      Glib::ustring str;
>      str = m_Entry1.get_text();
>      locale_from_utf8 (str);
> 
>      const char *szMessage= str.c_str();
>   
>      int nBytesSent = serial.SendData(szMessage, strlen(szMessage));

The line:

  locale_from_utf8(str);

does nothing.  If you want codeset conversion would have to do something
like:

  std::string locale_str(locale_from_utf8(str));

Note that a Glib::ustring object must hold utf8 for most purposes.

The following:

  const char *szMessage= str.c_str();  
  int nBytesSent = serial.SendData(szMessage, strlen(szMessage));

could be more efficiently expressed as:

  int nBytesSent = serial.SendData(locale_str.data(),
                                   locale_str.size());

or if you want to send utf8, by the following:

  int nBytesSent = serial.SendData(str.data(), str.raw().size());


The answer to your original question is that there is no type conversion
provided between Glib::ustring and const char*, just as std::string
provides no such conversion, for a number of good reasons.

Chris




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