mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Configurable parameter for DSL headwords' maximum size.
By default, it is unchanged, still 256. In those rare cases when users really need more lengthy headwords, they could adjust the config file, maxHeadwordSize parameter.
This commit is contained in:
parent
c40de2dbf6
commit
7496f5f80c
|
@ -900,14 +900,14 @@ static uint32_t buildBtreeNode( IndexedWords::const_iterator & nextIndex,
|
|||
return offset;
|
||||
}
|
||||
|
||||
void IndexedWords::addWord( wstring const & word, uint32_t articleOffset )
|
||||
void IndexedWords::addWord( wstring const & word, uint32_t articleOffset, unsigned int maxHeadwordSize )
|
||||
{
|
||||
wchar const * wordBegin = word.c_str();
|
||||
string::size_type wordSize = word.size();
|
||||
|
||||
// Safeguard us against various bugs here. Don't attempt adding words
|
||||
// which are freakishly huge.
|
||||
if ( wordSize > 256 )
|
||||
if ( wordSize > maxHeadwordSize )
|
||||
return;
|
||||
|
||||
// Skip any leading whitespace
|
||||
|
|
|
@ -178,7 +178,7 @@ struct IndexedWords: public map< string, vector< WordArticleLink > >
|
|||
/// Instead of adding to the map directly, use this function. It does folding
|
||||
/// itself, and for phrases/sentences it adds additional entries beginning with
|
||||
/// each new word.
|
||||
void addWord( wstring const & word, uint32_t articleOffset );
|
||||
void addWord( wstring const & word, uint32_t articleOffset, unsigned int maxHeadwordSize = 256U );
|
||||
|
||||
/// Differs from addWord() in that it only adds a single entry. We use this
|
||||
/// for zip's file names.
|
||||
|
|
13
config.cc
13
config.cc
|
@ -757,6 +757,15 @@ Class load() throw( exError )
|
|||
if ( !root.namedItem( "maxPictureWidth" ).isNull() )
|
||||
c.maxPictureWidth = root.namedItem( "maxPictureWidth" ).toElement().text().toInt();
|
||||
|
||||
if ( !root.namedItem( "maxHeadwordSize" ).isNull() )
|
||||
{
|
||||
unsigned int value = root.namedItem( "maxHeadwordSize" ).toElement().text().toUInt();
|
||||
if ( value != 0 ) // 0 is invalid value for our purposes
|
||||
{
|
||||
c.maxHeadwordSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -1405,6 +1414,10 @@ void save( Class const & c ) throw( exError )
|
|||
opt = dd.createElement( "maxPictureWidth" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.maxPictureWidth ) ) );
|
||||
root.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "maxHeadwordSize" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.maxHeadwordSize ) ) );
|
||||
root.appendChild( opt );
|
||||
}
|
||||
|
||||
QByteArray result( dd.toByteArray() );
|
||||
|
|
|
@ -415,12 +415,16 @@ struct Class
|
|||
|
||||
int maxPictureWidth; // Maximum picture width
|
||||
|
||||
/// Maximum size for the headwords.
|
||||
/// Bigger headwords won't be indexed. For now, only in DSL.
|
||||
unsigned int maxHeadwordSize;
|
||||
|
||||
QString editDictionaryCommandLine; // Command line to call external editor for dictionary
|
||||
|
||||
Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ),
|
||||
pinPopupWindow( false ), showingDictBarNames( false ),
|
||||
usingSmallIconsInToolbars( false ), maxDictionaryRefsInContextMenu( 20 ),
|
||||
maxPictureWidth( 0 )
|
||||
maxPictureWidth( 0 ), maxHeadwordSize ( 256U )
|
||||
{}
|
||||
Group * getGroup( unsigned id );
|
||||
Group const * getGroup( unsigned id ) const;
|
||||
|
|
6
dsl.cc
6
dsl.cc
|
@ -1476,7 +1476,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
|||
vector< string > const & fileNames,
|
||||
string const & indicesDir,
|
||||
Dictionary::Initializing & initializing,
|
||||
int maxPictureWidth )
|
||||
int maxPictureWidth, unsigned int maxHeadwordSize )
|
||||
throw( std::exception )
|
||||
{
|
||||
vector< sptr< Dictionary::Class > > dictionaries;
|
||||
|
@ -1765,7 +1765,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
|||
{
|
||||
unescapeDsl( *j );
|
||||
normalizeHeadword( *j );
|
||||
indexedWords.addWord( *j, descOffset );
|
||||
indexedWords.addWord( *j, descOffset, maxHeadwordSize );
|
||||
}
|
||||
|
||||
++articleCount;
|
||||
|
@ -1829,7 +1829,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
|||
unescapeDsl( (*i).headword );
|
||||
normalizeHeadword( (*i).headword );
|
||||
|
||||
indexedWords.addWord( (*i).headword, descOffset );
|
||||
indexedWords.addWord( (*i).headword, descOffset, maxHeadwordSize );
|
||||
|
||||
++articleCount;
|
||||
++wordCount;
|
||||
|
|
2
dsl.hh
2
dsl.hh
|
@ -16,7 +16,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
|||
vector< string > const & fileNames,
|
||||
string const & indicesDir,
|
||||
Dictionary::Initializing &,
|
||||
int maxPictureWidth )
|
||||
int maxPictureWidth, unsigned int maxHeadwordSize )
|
||||
throw( std::exception );
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ LoadDictionaries::LoadDictionaries( Config::Class const & cfg ):
|
|||
paths( cfg.paths ), soundDirs( cfg.soundDirs ), hunspell( cfg.hunspell ),
|
||||
transliteration( cfg.transliteration ),
|
||||
exceptionText( "Load did not finish" ), // Will be cleared upon success
|
||||
maxPictureWidth( cfg.maxPictureWidth )
|
||||
maxPictureWidth( cfg.maxPictureWidth ),
|
||||
maxHeadwordSize( cfg.maxHeadwordSize )
|
||||
{
|
||||
// Populate name filters
|
||||
|
||||
|
@ -131,7 +132,8 @@ void LoadDictionaries::handlePath( Config::Path const & path )
|
|||
|
||||
{
|
||||
vector< sptr< Dictionary::Class > > dslDictionaries =
|
||||
Dsl::makeDictionaries( allFiles, FsEncoding::encode( Config::getIndexDir() ), *this, maxPictureWidth );
|
||||
Dsl::makeDictionaries(
|
||||
allFiles, FsEncoding::encode( Config::getIndexDir() ), *this, maxPictureWidth, maxHeadwordSize );
|
||||
|
||||
dictionaries.insert( dictionaries.end(), dslDictionaries.begin(),
|
||||
dslDictionaries.end() );
|
||||
|
|
|
@ -24,6 +24,7 @@ class LoadDictionaries: public QThread, public Dictionary::Initializing
|
|||
std::vector< sptr< Dictionary::Class > > dictionaries;
|
||||
std::string exceptionText;
|
||||
int maxPictureWidth;
|
||||
unsigned int maxHeadwordSize;
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue