Created
January 10, 2012 10:14
-
-
Save plq/1588339 to your computer and use it in GitHub Desktop.
Qt ile encoding testi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QString> | |
#include <QTextCodec> | |
#include <iostream> | |
int main(int argc, char *argv[]) { | |
const char *p = "kıracağım"; | |
// Kaynak kod editörünün encoding'inin utf8 olduğunu varsayarsak; | |
QTextCodec *utf8 = QTextCodec::codecForName("utf8"); | |
QTextCodec *cp_1254 = QTextCodec::codecForName("Windows-1254"); | |
QString str = utf8->toUnicode(p); // <- simdi elimizde dogru yorumlanmis string var | |
QByteArray byte_array = cp_1254->fromUnicode(str); // simdi elimizde cp-1254 var | |
for (const char *p2=byte_array.constData(); *p2; ++p2) { | |
std::cout << std::hex << (unsigned)*p2 << " "; | |
} | |
std::cout << std::endl; | |
// ya da soyle gostereyim: | |
std::cout << cp_1254->fromUnicode(str).toPercentEncoding().constData() << std::endl; // cp-1254'u percent encoding yaptik | |
std::cout << utf8->fromUnicode(str).toPercentEncoding().constData() << std::endl; // utf8'i percent encoding yaptik | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6b fffffffd 72 61 63 61 fffffff0 fffffffd 6d | |
k%FDraca%F0%FDm | |
k%C4%B1raca%C4%9F%C4%B1m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment