Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / plugins / stardict / UncompressedReader.cpp
index 15102ef..6b75e90 100644 (file)
@@ -1,4 +1,33 @@
+/*******************************************************************************
+
+    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) :
@@ -6,33 +35,51 @@ UncompressedReader::UncompressedReader(QObject *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[1];
 
-    _stream.readRawData(c, 1);
-    return QChar(c[0]);
+QChar UncompressedReader::readChar() {
+    char c[4]={0};
+    QString cha;
+
+    _stream.readRawData(c,1);
+    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);
+    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;
@@ -42,48 +89,36 @@ QString UncompressedReader::readKeyword() {
         result += c;
         c = readChar();
     }
-
     return result;
 }
 
-QString UncompressedReader::readString(qint32 offset, qint32 len) {
-    char* buf;
-    buf = new char[len];
-
-    _file.seek(offset);
-    _stream.readRawData(buf, len);
-
-    QString result(buf);
-    delete [] buf;
-    return result;
-}
 
-QString UncompressedReader::readString(qint64 offset, qint32 len) {
+QByteArray UncompressedReader::readString(qint64 offset, qint32 len) {
     char* buf;
     buf = new char[len];
 
     _file.seek(offset);
     _stream.readRawData(buf, len);
 
-    QString result(buf);
+    QByteArray result(buf, len);
     delete [] buf;
     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;
 }