2016-03-23 2:08 GMT+03:00 deloptes <deloptes(a)gmail.com>om>:
Hi all,
I need some help again.
Which is the preferred function to use when creating TQString from
std::string and how can I make sure that I end up with Utf-8.
The thing is that input in std::string can be either UTF-8 or not UTF-8.
What is the standard way of doing this in TDE (TQt)?
I am really confused, because I was looking in some KDE3/TDE code and I see
both used.
My problem is that some older phones would most likely lack UTF and newer
would do only UTF. So how can I make sure to "speak the right language"
with them?
A hint would be appreciated.
regards
1) If you construct a string from a const char * c-string in your code
you better use fromLatin1(). e.g TQString::fromLatin1 ("blabla")
1.1) If the string includes some local symbols or some non-latin1
symbols somewhy, but your source xode is strictly in utf8 you may use
TQString::fromUtf8 ("10°") [note the degree sign], But this is kinda
dirty practice
2) If you receive a string from OS e.g. a file path from system calls,
you would likely should use TQString::fromLocal8bit(), Note that it
will decode from utf8 on most modern linux boxes.
3) If you receive a string from some third party module or where ever
else you should follow to it's documentation. It may return a text in
some other encoding, and you will have to use TQTextCodec (or whatever
it's called).
3.1) If you are not sure if it will give you either a latin1 or utf8
string, You are safe to use TQString::fromUtf8()
Note that it's quite safe to use fromUtf8() everywhere instead of
fromLatin1(), in most of cases you risk to get just some performance
overhead...