diff --git a/btreeidx.cc b/btreeidx.cc index e0761c10..3667abe1 100644 --- a/btreeidx.cc +++ b/btreeidx.cc @@ -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( ;; ) diff --git a/config.cc b/config.cc index e028ad90..cf226dbc 100644 --- a/config.cc +++ b/config.cc @@ -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; } diff --git a/dsl_details.cc b/dsl_details.cc index 965ce1c6..569a2d55 100644 --- a/dsl_details.cc +++ b/dsl_details.cc @@ -12,6 +12,7 @@ #include #include + #include 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.