[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/utils/ktranslator
From: Raul Fernandes <rgfbr () yahoo ! com ! br>
Date: 2006-01-31 23:49:14
Message-ID: 1138751354.702144.15795.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 504412 by rgfbr:
Dictd plugin can return more than 1 result now
M +1 -0 ChangeLog
M +71 -60 plugins/dictd/dictzip.cpp
M +2 -5 plugins/dictd/dictzip.h
--- trunk/extragear/utils/ktranslator/ChangeLog #504411:504412
@@ -3,6 +3,7 @@
Fix a crash when no dictionaries are selected and click in Edit or Remove
StarDict plugin
Optimization in Dictd plugin start
+ Dictd plugin can return more than 1 result now
2006-01-29
Fix a small bug (Webster DICT dictionary doesn't works correctly)
--- trunk/extragear/utils/ktranslator/plugins/dictd/dictzip.cpp #504411:504412
@@ -106,7 +106,7 @@
}
#ifndef NOPTIMIZE
- QString line, headword;
+ QString line;
struct entry entry;
dic.clear();
int pos, pos1;
@@ -116,7 +116,7 @@
idxFile->readLine( line, 1024 );
pos = line.find( '\t' );
- headword = QString::fromUtf8( line.left( pos ).lower().local8Bit() );
+ entry.headword = QString::fromUtf8( line.left( pos ).lower().local8Bit() );
// Catch the position of definition in definition file
// The value is coded in base64
@@ -129,7 +129,7 @@
pos1++;
entry.size = b64_decode( line.right( line.length() - pos1 ).remove('\n').local8Bit() );
- dic.insert( headword, entry );
+ dic.append( entry );
}
idxFile->close();
#endif
@@ -219,11 +219,18 @@
//kdDebug() << "DictZip::search()" << endl;
struct entry entry;
+ // Stores the decompressed data
+ QCString result;
+ QString resultFinal;
+
+
#ifndef NOPTIMIZE
// Find the headword in index file
- Dictionary::ConstIterator it = dic.find( word );
- if( it == dic.constEnd() ) return QString::null;
- entry = it.data();
+ Dictionary::ConstIterator it;
+ for ( it = dic.constBegin(); it != dic.constEnd(); ++it )
+ {
+ if( (*it).headword != word ) continue;
+ entry = *it;
#else
QString line, headword;
bool found = false;
@@ -235,9 +242,11 @@
{
idxFile->readLine( line, 1024 );
pos = line.find( '\t' );
- headword = QString::fromUtf8( line.left( pos ).local8Bit() );
+ headword = QString::fromUtf8( line.left( pos ).lower().local8Bit() );
- if( QString::localeAwareCompare( headword, word ) != 0 ) continue;
+ if( QString::localeAwareCompare( headword, word ) != 0 )
+ if( found ) break;
+ else continue;
found = true;
// Catch the position of definition in definition file
@@ -253,69 +262,71 @@
// The value is coded in base64
entry.size = b64_decode( headword.local8Bit() );
- // Word found. Break the loop.
- break;
- }
- idxFile->close();
-
- // If not found, return a null string
- if( !found ) return QString::null;
#endif
- // Check if the definition file is compressed
- if( isCompressed )
- {
- ulong a = 0;
+ // Check if the definition file is compressed
+ if( isCompressed )
+ {
+ ulong a = 0;
- // Calculate how many chunks we have to skip
- uint chunk = entry.position / CHLEN ;
- // Calculate the position of definition in chunk
- uint pos = entry.position % CHLEN;
+ // Calculate how many chunks we have to skip
+ uint chunk = entry.position / CHLEN ;
+ // Calculate the position of definition in chunk
+ uint pos = entry.position % CHLEN;
- // Size of the chunk we are looking for
- unsigned long chunkLen = offsets[chunk];
- // If the word is in the end of chunk, we have to decompress two chunks
- if( (pos + entry.size) > CHLEN ) chunkLen += offsets[chunk + 1];
+ // Size of the chunk we are looking for
+ unsigned long chunkLen = offsets[chunk];
+ // If the word is in the end of chunk, we have to decompress two chunks
+ if( (pos + entry.size) > CHLEN ) chunkLen += offsets[chunk + 1];
- // How many bytes we have to skip
- unsigned long skip = 0;
- for(uint a=0;a<chunk;a++) skip += offsets[a];
+ // How many bytes we have to skip
+ unsigned long skip = 0;
+ for(uint a=0;a<chunk;a++) skip += offsets[a];
- // Stores the compressed data
- QByteArray data( chunkLen + 1 );
- data[chunkLen] = '\0';
+ // Stores the compressed data
+ QByteArray data( chunkLen + 1 );
+ data[chunkLen] = '\0';
- // Stores the decompressed data
- QCString result;
+ // Definition file
+ file->open( IO_ReadOnly );
- // Definition file
- file->open( IO_ReadOnly );
+ // Jump to chunk we are looking for
+ file->at( offset + skip );
- // Jump to chunk we are looking for
- file->at( offset + skip );
+ // Get the compressed data
+ for(a = 0; a < chunkLen; a++) data[a] = file->getch();
+ data[a] = '\0';
+ file->close();
- // Get the compressed data
- for(a = 0; a < chunkLen; a++) data[a] = file->getch();
- data[a] = '\0';
- file->close();
+ // Decompress the data
+ result = deflate( data );
+ // Returns only the definition
+ resultFinal += QString::fromUtf8( result.mid( pos, entry.size ) );
+ resultFinal += "\n";
+ }else{
+ // The file is not compressed
+ file->open( IO_ReadOnly );
+ // Jump to position of definition
+ file->at( entry.position );
+ // Get the definition
+ result.fill( ' ', entry.size );
+ for( uint a = 0; a < entry.size; a++ ) result[a] = file->getch();
+ result[entry.size] = '\0';
+ file->close();
+ resultFinal += QString::fromUtf8( result.data() );
+ resultFinal += "\n";
+ }
+ }
+#ifndef NOPTIMIZE
+ // Return the result
+ return resultFinal;
+#else
+ idxFile->close();
- // Decompress the data
- result = deflate( data );
- // Returns only the definition
- return QString::fromUtf8( result.mid( pos, entry.size ) );
- }else{
- // The file is not compressed
- file->open( IO_ReadOnly );
- // Jump to position of definition
- file->at( entry.position );
- // Get the definition
- QCString result( entry.size + 1 );
- for( uint a = 0; a < entry.size; a++ ) result[a] = file->getch();
- result[entry.size] = '\0';
- file->close();
- // Return the result
- return QString::fromUtf8( result.data() );
- }
+ // If not found, return a null string
+ if( !found ) return QString::null;
+ return resultFinal;
+#endif
}
--- trunk/extragear/utils/ktranslator/plugins/dictd/dictzip.h #504411:504412
@@ -23,10 +23,6 @@
#include <qstring.h>
#include <qvaluelist.h>
-#ifndef NOPTIMIZE
-#include <qmap.h>
-#endif
-
class QFile;
/**
@@ -71,11 +67,12 @@
unsigned long offset;
struct entry{
+ QString headword;
unsigned long position;
unsigned long size;
};
#ifndef NOPTIMIZE
- typedef QMap<QString, entry>Dictionary;
+ typedef QValueList<entry> Dictionary;
Dictionary dic;
#endif
protected:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic