diff --git a/dsl.cc b/dsl.cc index f9f1e1b9..6912a59c 100644 --- a/dsl.cc +++ b/dsl.cc @@ -577,7 +577,7 @@ void DslDictionary::loadArticle( uint32_t address, list< wstring > lst; - expandOptionalParts( tildeValue, lst ); + expandOptionalParts( tildeValue, &lst ); if ( lst.size() ) // Should always be tildeValue = lst.front(); @@ -597,7 +597,7 @@ void DslDictionary::loadArticle( uint32_t address, str = Folding::applySimpleCaseOnly( str ); list< wstring > lst; - expandOptionalParts( str, lst ); + expandOptionalParts( str, &lst ); // Does one of the results match the requested word? If so, we'd choose // it as our headword. @@ -1500,7 +1500,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( if ( keys.size() ) expandTildes( curString, keys.front() ); - expandOptionalParts( curString, keys ); + expandOptionalParts( curString, &keys ); if ( !abrvScanner.readNextLine( curString, curOffset ) || curString.empty() ) { @@ -1602,7 +1602,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( list< wstring > allEntryWords; processUnsortedParts( curString, true ); - expandOptionalParts( curString, allEntryWords ); + expandOptionalParts( curString, &allEntryWords ); uint32_t articleOffset = curOffset; @@ -1629,7 +1629,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( processUnsortedParts( curString, true ); expandTildes( curString, allEntryWords.front() ); - expandOptionalParts( curString, allEntryWords ); + expandOptionalParts( curString, &allEntryWords ); } if ( !hasString ) diff --git a/dsl_details.cc b/dsl_details.cc index 0a105ab7..a2b14cb3 100644 --- a/dsl_details.cc +++ b/dsl_details.cc @@ -873,9 +873,13 @@ void processUnsortedParts( wstring & str, bool strip ) } } -void expandOptionalParts( wstring & str, list< wstring > & result, - size_t x ) +void expandOptionalParts( wstring & str, list< wstring > * result, + size_t x, bool inside_recurse ) { + list< wstring > expanded; + list< wstring > * headwords; + headwords = inside_recurse ? result : &expanded; + for( ; x < str.size(); ) { wchar ch = str[ x ]; @@ -918,7 +922,7 @@ void expandOptionalParts( wstring & str, list< wstring > & result, wstring removed( str, 0, x ); removed.append( str, y + 1, str.size() - y - 1 ); - expandOptionalParts( removed, result, x ); + expandOptionalParts( removed, headwords, x, true ); } break; @@ -933,10 +937,14 @@ void expandOptionalParts( wstring & str, list< wstring > & result, wstring removed( str, 0, x ); // Limit the amount of results to avoid excessive resource consumption - if ( result.size() < 32 ) - result.push_back( removed ); + if ( headwords->size() < 32 ) + headwords->push_back( removed ); else + { + if( !inside_recurse ) + result->merge( expanded ); return; + } } } @@ -956,8 +964,10 @@ void expandOptionalParts( wstring & str, list< wstring > & result, } // Limit the amount of results to avoid excessive resource consumption - if ( result.size() < 32 ) - result.push_back( str ); + if ( headwords->size() < 32 ) + headwords->push_back( str ); + if( !inside_recurse ) + result->merge( expanded ); } void expandTildes( wstring & str, wstring const & tildeReplacement ) diff --git a/dsl_details.hh b/dsl_details.hh index 97b0af4e..9d9ab404 100644 --- a/dsl_details.hh +++ b/dsl_details.hh @@ -161,8 +161,8 @@ void processUnsortedParts( wstring & str, bool strip ); /// Expands optional parts of a headword (ones marked with parentheses), /// producing all possible combinations where they are present or absent. -void expandOptionalParts( wstring & str, list< wstring > & result, - size_t x = 0 ); +void expandOptionalParts( wstring & str, list< wstring > * result, + size_t x = 0, bool inside_recurse = false ); /// Expands all unescaped tildes, inserting tildeReplacement text instead of /// them.