mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
commit
5230d254a8
|
@ -184,8 +184,8 @@ InputPhrase Preferences::sanitizeInputPhrase( QString const & inputPhrase ) cons
|
||||||
|
|
||||||
if( limitInputPhraseLength && inputPhrase.size() > inputPhraseLengthLimit )
|
if( limitInputPhraseLength && inputPhrase.size() > inputPhraseLengthLimit )
|
||||||
{
|
{
|
||||||
gdWarning( "Ignoring an input phrase %d symbols long. The configured maximum input phrase length is %d symbols.",
|
gdDebug( "Ignoring an input phrase %d symbols long. The configured maximum input phrase length is %d symbols.",
|
||||||
inputPhrase.size(), inputPhraseLengthLimit );
|
inputPhrase.size(), inputPhraseLengthLimit );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Dsl {
|
namespace Dsl {
|
||||||
|
@ -164,12 +165,37 @@ wstring ArticleDom::Node::renderAsText( bool stripTrsTag ) const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if src == 'm' and dest is 'mX', where X is a digit
|
namespace {
|
||||||
static inline bool checkM( wstring const & dest, wstring const & src )
|
|
||||||
|
/// @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,
|
ArticleDom::ArticleDom( wstring const & str, string const & dictName,
|
||||||
wstring const & headword_):
|
wstring const & headword_):
|
||||||
root( Node::Tag(), wstring(), wstring() ), stringPos( str.c_str() ),
|
root( Node::Tag(), wstring(), wstring() ), stringPos( str.c_str() ),
|
||||||
|
@ -375,7 +401,7 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName,
|
||||||
|
|
||||||
if ( !isClosing )
|
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
|
// Opening an 'mX' or 'm' tag closes any previous 'm' tag
|
||||||
closeTag( U"m" , stack, false );
|
closeTag( U"m" , stack, false );
|
||||||
|
@ -630,7 +656,24 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName,
|
||||||
|
|
||||||
if ( stack.size() )
|
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;
|
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
|
// All tags above [m] tag will be closed and reopened after
|
||||||
// to avoid break this tag by closing some other tag.
|
// to avoid break this tag by closing some other tag.
|
||||||
|
|
Loading…
Reference in a new issue