mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
Dsl: A little improve of unmatched tags diagnostic
This commit is contained in:
parent
94bbeb650a
commit
362acce554
12
dsl.cc
12
dsl.cc
|
@ -250,7 +250,7 @@ private:
|
|||
wstring & articleText );
|
||||
|
||||
/// Converts DSL language to an Html.
|
||||
string dslToHtml( wstring const & );
|
||||
string dslToHtml( wstring const &, wstring const & headword = wstring() );
|
||||
|
||||
// Parts of dslToHtml()
|
||||
string nodeToHtml( ArticleDom::Node const & );
|
||||
|
@ -715,12 +715,12 @@ void DslDictionary::loadArticle( uint32_t address,
|
|||
articleText.clear();
|
||||
}
|
||||
|
||||
string DslDictionary::dslToHtml( wstring const & str )
|
||||
string DslDictionary::dslToHtml( wstring const & str, wstring const & headword )
|
||||
{
|
||||
// Normalize the string
|
||||
wstring normalizedStr = gd::normalize( str );
|
||||
|
||||
ArticleDom dom( normalizedStr );
|
||||
ArticleDom dom( normalizedStr, getName(), headword );
|
||||
|
||||
optionalPartNom = 0;
|
||||
|
||||
|
@ -1330,7 +1330,7 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,
|
|||
|
||||
articleData.clear();
|
||||
|
||||
ArticleDom dom( gd::normalize( articleText ) );
|
||||
ArticleDom dom( gd::normalize( articleText ), getName(), articleHeadword );
|
||||
|
||||
articleText.clear();
|
||||
|
||||
|
@ -1477,7 +1477,7 @@ void DslArticleRequest::run()
|
|||
if( displayedHeadword.size() == 1 && displayedHeadword[0] == '<' ) // Fix special case - "<" header
|
||||
articleText += "<"; // dslToHtml can't handle it correctly.
|
||||
else
|
||||
articleText += dict.dslToHtml( displayedHeadword );
|
||||
articleText += dict.dslToHtml( displayedHeadword, displayedHeadword );
|
||||
|
||||
/// After this may be expand button will be inserted
|
||||
|
||||
|
@ -1490,7 +1490,7 @@ void DslArticleRequest::run()
|
|||
articleAfter += " dir=\"rtl\"";
|
||||
articleAfter += ">";
|
||||
|
||||
articleAfter += dict.dslToHtml( articleBody );
|
||||
articleAfter += dict.dslToHtml( articleBody, displayedHeadword );
|
||||
articleAfter += "</div>";
|
||||
articleAfter += "</span>";
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "gddebug.hh"
|
||||
#include "ufile.hh"
|
||||
#include "wstring_qt.hh"
|
||||
#include "utf8.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <wctype.h>
|
||||
|
@ -62,9 +63,12 @@ static inline bool checkM( wstring const & dest, wstring const & src )
|
|||
dest[ 0 ] == L'm' && iswdigit( dest[ 1 ] ) );
|
||||
}
|
||||
|
||||
ArticleDom::ArticleDom( wstring const & str ):
|
||||
ArticleDom::ArticleDom( wstring const & str, string const & dictName,
|
||||
wstring const & headword_):
|
||||
root( Node::Tag(), wstring(), wstring() ), stringPos( str.c_str() ),
|
||||
transcriptionCount( 0 )
|
||||
transcriptionCount( 0 ),
|
||||
dictionaryName( dictName ),
|
||||
headword( headword_ )
|
||||
{
|
||||
list< Node * > stack; // Currently opened tags
|
||||
|
||||
|
@ -599,8 +603,13 @@ void ArticleDom::closeTag( wstring const & name,
|
|||
else
|
||||
if ( warn )
|
||||
{
|
||||
qWarning() << "Warning: no corresponding opening tag for closing tag" <<
|
||||
gd::toQString( name ) << "found.";
|
||||
if( !dictionaryName.empty() )
|
||||
gdWarning( "Warning: no corresponding opening tag for closing tag \"%s\" found in \"%s\", article \"%s\".",
|
||||
gd::toQString( name ).toUtf8().data(), dictionaryName.c_str(),
|
||||
gd::toQString( headword ).toUtf8().data() );
|
||||
else
|
||||
gdWarning( "Warning: no corresponding opening tag for closing tag \"%s\" found.",
|
||||
gd::toQString( name ).toUtf8().data() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,8 @@ struct ArticleDom
|
|||
|
||||
/// Does the parse at construction. Refer to the 'root' member variable
|
||||
/// afterwards.
|
||||
ArticleDom( wstring const & );
|
||||
ArticleDom( wstring const &, string const & dictName = string(),
|
||||
wstring const & headword_ = wstring() );
|
||||
|
||||
/// Root of DOM's tree
|
||||
Node root;
|
||||
|
@ -83,6 +84,10 @@ private:
|
|||
unsigned transcriptionCount; // >0 = inside a [t] tag
|
||||
|
||||
void nextChar() throw( eot );
|
||||
|
||||
/// Infomation for diagnostic purposes
|
||||
string dictionaryName;
|
||||
wstring headword;
|
||||
};
|
||||
|
||||
/// A adapted version of Iconv which takes Dsl encoding and decodes to wchar.
|
||||
|
|
Loading…
Reference in a new issue