Merge branch 'staged' of github.com:xiaoyifang/goldendict into staged

This commit is contained in:
Xiao YiFang 2022-11-12 09:16:23 +08:00
commit e3d904f8b8
3 changed files with 54 additions and 11 deletions

View file

@ -1313,12 +1313,12 @@ void BtreeIndex::findSingleNodeHeadwords( uint32_t offsets,
vector< char > extLeaf;
// A node
// A node
readNode( currentNodeOffset, extLeaf );
leaf = &extLeaf.front();
leaf = &extLeaf.front();
leafEnd = leaf + extLeaf.size();
// A leaf
// A leaf
chainPtr = leaf + sizeof( uint32_t );
for( ;; )

View file

@ -184,8 +184,8 @@ InputPhrase Preferences::sanitizeInputPhrase( QString const & inputPhrase ) cons
if( limitInputPhraseLength && inputPhrase.size() > inputPhraseLengthLimit )
{
gdWarning( "Ignoring an input phrase %d symbols long. The configured maximum input phrase length is %d symbols.",
inputPhrase.size(), inputPhraseLengthLimit );
gdDebug( "Ignoring an input phrase %d symbols long. The configured maximum input phrase length is %d symbols.",
inputPhrase.size(), inputPhraseLengthLimit );
return result;
}

View file

@ -12,6 +12,7 @@
#include <stdio.h>
#include <wctype.h>
#include <algorithm>
namespace Dsl {
@ -164,12 +165,37 @@ wstring ArticleDom::Node::renderAsText( bool stripTrsTag ) const
return result;
}
// Returns true if src == 'm' and dest is 'mX', where X is a digit
static inline bool checkM( wstring const & dest, wstring const & src )
namespace {
/// @return true if @p tagName equals "mN" where N is a digit
bool is_mN( wstring const & tagName )
{
return ( src == U"m" && dest.size() == 2 && dest[ 0 ] == L'm' && iswdigit( dest[ 1 ] ) );
return tagName.size() == 2 && tagName[ 0 ] == U'm' && iswdigit( tagName[ 1 ] );
}
bool isAnyM( wstring const & tagName )
{
return tagName == U"m" || is_mN( tagName );
}
bool checkM( wstring const & dest, wstring const & src )
{
return src == U"m" && is_mN( dest );
}
/// Closing the [mN] tags is optional. Quote from https://documentation.help/ABBYY-Lingvo8/paragraph_form.htm:
/// Any paragraph from this tag until the end of card or until system meets an «[/m]» (margin shift toggle off) tag
struct MustTagBeClosed
{
bool operator()( ArticleDom::Node const * tag ) const
{
Q_ASSERT( tag->isTag );
return !isAnyM( tag->tagName );
}
};
} // unnamed namespace
ArticleDom::ArticleDom( wstring const & str, string const & dictName,
wstring const & headword_):
root( Node::Tag(), wstring(), wstring() ), stringPos( str.c_str() ),
@ -375,7 +401,7 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName,
if ( !isClosing )
{
if( name == U"m" || ( name.size() == 2 && name[ 0 ] == L'm' && iswdigit( name[ 1 ] ) ) )
if( isAnyM( name ) )
{
// Opening an 'mX' or 'm' tag closes any previous 'm' tag
closeTag( U"m" , stack, false );
@ -630,7 +656,24 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName,
if ( stack.size() )
{
GD_FDPRINTF( stderr, "Warning: %u tags were unclosed.\n", (unsigned) stack.size() );
list< Node * >::iterator it = std::find_if( stack.begin(), stack.end(), MustTagBeClosed() );
if( it == stack.end() )
return; // no unclosed tags that must be closed => nothing to warn about
QByteArray const firstTagName = gd::toQString( ( *it )->tagName ).toUtf8();
++it;
unsigned const unclosedTagCount = 1 + std::count_if( it, stack.end(), MustTagBeClosed() );
if( dictName.empty() )
{
gdWarning( "Warning: %u tag(s) were unclosed, first tag name \"%s\".\n",
unclosedTagCount, firstTagName.constData() );
}
else
{
gdWarning( "Warning: %u tag(s) were unclosed in \"%s\", article \"%s\", first tag name \"%s\".\n",
unclosedTagCount, dictName.c_str(), gd::toQString( headword ).toUtf8().constData(),
firstTagName.constData() );
}
}
}
@ -640,7 +683,7 @@ void ArticleDom::openTag( wstring const & name,
{
list< Node > nodesToReopen;
if( name == U"m" || checkM( name, U"m" ) )
if( isAnyM( name ) )
{
// All tags above [m] tag will be closed and reopened after
// to avoid break this tag by closing some other tag.