fix some bugs
[mdictionary] / src / plugins / stardict / CompressedReader.cpp
index d142934..33a9744 100644 (file)
@@ -53,40 +53,44 @@ void CompressedReader::close() {
 
 
 QChar CompressedReader::readChar() {
-    char c[2]={0};
+    char c[4]={0};
+    QString cha;
+
     gzread(_file, c, 1);
-    QString cha(QString::fromUtf8(c));
-    if(!cha.at(0).isLetter() && c[0]!=0){
-        gzread(_file, c, 1);
-        cha=QString::fromUtf8(c);
+    if(((unsigned char)c[0])>127){
+        gzread(_file, c+1, 1);
+        if(((unsigned char)c[1])>127 && ((unsigned char)c[1])<192){
+            gzread(_file, c+2, 1);
+            if(((unsigned char)c[2])>127 && ((unsigned char)c[2])<192)
+                gzread(_file, c+3, 1);
+        }
     }
+
+    cha=QString::fromUtf8(c);
     return cha.at(0);
 }
 
 qint32 CompressedReader::readInt32BigEndian() {
     qint32 value;
     gzread(_file, (void*)(&value), 4);
-
     return qFromBigEndian(value);
 }
 
 qint64 CompressedReader::readInt64BigEndian() {
     qint64 value;
     gzread(_file, (void*)(&value), 8);
-
     return value;
 }
 
 QString CompressedReader::readKeyword() {
     QString result;
     QChar c;
-    c = readChar();
 
+    c = readChar();
     while(c != '\0') {
         result += c;
         c = readChar();
     }
-
     return result;
 }