On quarta-feira, 31 de julho de 2013 19:39:28, Scott Aron Bloom wrote: > QTextCodec * codec = QTextCodec::codecForName( "UTF-8" ); > QString a = codec->toUnicode( "a" ); > If ( a.isEmpty() ) > // don't Show > QChar aChar = tmp.at( 0 ); > If ( aChar.unicode() != 'a' ) > // don't show > > This look ok?
You want the fromUnicode operation. We know what the UTF-16 representation of U+0061 LATIN SMALL LETTER A is (one 16-bit word containing the value 0x61). We need to test how it's encoded in this codec. QChar letterA(0x61); if (codec->fromUnicode(&letterA, 1) != "a") // [1] // can't use for all ASCII-compatible codecs, the result will be "a". In fact, that is true for all codecs that Qt 4 ships, except for UTF-16 and UTF-32. In Qt 5, because we use ICU now, that's no longer true. It's also not true if someone else installs their own codecs. [1] comparing to "a" is a trick that works only if your execution charset is also ASCII-compatible. In 20 years doing software development, I have yet to see an environment that isn't. The ability to have different source, translation and execution charsets is a legacy in C and C++ from the olden days. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest