Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / plugins / stardict / UncompressedReader.cpp
index d4370c5..6b75e90 100644 (file)
@@ -1,42 +1,85 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*!
+    \file UncompressedReader.cpp
+    \brief Class implementing StarDictReader interface and handling
+  reading from uncompressed files
+
+    \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+ */
+
 #include "UncompressedReader.h"
 #include "QDebug"
 
+
 UncompressedReader::UncompressedReader(QObject *parent) :
         StarDictReader(parent) {
 
 }
 
+
 UncompressedReader::UncompressedReader(QString filename, QObject *parent) :
 StarDictReader(parent) {
     open(filename);
 }
 
+
 UncompressedReader::~UncompressedReader() {
     if(_file.isOpen())
         _file.close();
 }
 
+
 bool UncompressedReader::open(QString file) {
     _file.setFileName(file);
     _stream.setDevice(&_file);
     return _file.open(QFile::ReadOnly);
 }
 
+
 void UncompressedReader::close() {
     _file.close();
 }
 
+
 QChar UncompressedReader::readChar() {
-    char c[2]={0};
+    char c[4]={0};
+    QString cha;
+
     _stream.readRawData(c,1);
-    QString cha(QString::fromUtf8(c));
-    if(!cha.at(0).isLetter() && c[0]!=0){
+    if(((unsigned char)c[0])>239)
+        _stream.readRawData(c+1,3);
+    else if(((unsigned char)c[0])>223)
+        _stream.readRawData(c+1,2);
+    else if(((unsigned char)c[0])>191)
         _stream.readRawData(c+1,1);
-        cha=QString::fromUtf8(c);
-    }
+    else if(((unsigned char)c[0])>127)
+        qDebug()<<"error - starDict - read wordList from UTF-8";
+
+    cha=QString::fromUtf8(c);
+
     return cha.at(0);
 }
 
+
 QString UncompressedReader::readKeyword() {
     QString result;
     QChar c;
@@ -46,7 +89,6 @@ QString UncompressedReader::readKeyword() {
         result += c;
         c = readChar();
     }
-
     return result;
 }
 
@@ -63,20 +105,20 @@ QByteArray UncompressedReader::readString(qint64 offset, qint32 len) {
     return result;
 }
 
+
 qint32 UncompressedReader::readInt32BigEndian() {
     _stream.setByteOrder(QDataStream::BigEndian);
     qint32 value;
     _stream>>value;
     _stream.setByteOrder(QDataStream::LittleEndian);
-
     return value;
 }
 
+
 qint64 UncompressedReader::readInt64BigEndian() {
     _stream.setByteOrder(QDataStream::BigEndian);
     qint64 value;
     _stream>>value;
     _stream.setByteOrder(QDataStream::LittleEndian);
-
     return value;
 }