Difference between revisions of "Unicode"
|(One intermediate revision by one user not shown)|
|Line 27:||Line 27:|
Latest revision as of 08:50, 16 May 2009
Clearly, every text file has an encoding, that means, you must know if two bytes form one character to display, one byte, or the characters have mixed byte length. Unicode defines every character in the world.
Here is some practice: Store a file containing
in file.txt. Do:
tweedleburg:~ # cat >file.txt hellö world tweedleburg:~ # cat file.txt hellö world tweedleburg:~ # hexdump -C file.txt 00000000 68 65 6c 6c c3 b6 20 77 6f 72 6c 64 0a |hell.. world.| 0000000d
This means, every "normal" character has been stored in 1 byte, every umlaut in 2 bytes. That is unicode's UTF-8 encoding
To show what Qt understands when it reads UTF8, we store a file with the content
nothing else. The following code outputs the code:
QFile inputfile(args->url(0).fileName()); inputfile.open(QIODevice::ReadOnly); inputfilecontent = inputfile.read(inputfile.bytesAvailable()); kDebug() << "inputfilecontent.data()"<<(byte)inputfilecontent.data(); kDebug() << "inputfilecontent.data()"<<(byte)inputfilecontent.data();
For little endian systems, ü UTF8 encoded delivers