Dsl: A little improve of unmatched tags diagnostic

This commit is contained in:
Abs62 2014-04-18 16:34:44 +04:00
parent 94bbeb650a
commit 362acce554
3 changed files with 25 additions and 11 deletions

12
dsl.cc
View file

@ -250,7 +250,7 @@ private:
wstring & articleText ); wstring & articleText );
/// Converts DSL language to an Html. /// Converts DSL language to an Html.
string dslToHtml( wstring const & ); string dslToHtml( wstring const &, wstring const & headword = wstring() );
// Parts of dslToHtml() // Parts of dslToHtml()
string nodeToHtml( ArticleDom::Node const & ); string nodeToHtml( ArticleDom::Node const & );
@ -715,12 +715,12 @@ void DslDictionary::loadArticle( uint32_t address,
articleText.clear(); articleText.clear();
} }
string DslDictionary::dslToHtml( wstring const & str ) string DslDictionary::dslToHtml( wstring const & str, wstring const & headword )
{ {
// Normalize the string // Normalize the string
wstring normalizedStr = gd::normalize( str ); wstring normalizedStr = gd::normalize( str );
ArticleDom dom( normalizedStr ); ArticleDom dom( normalizedStr, getName(), headword );
optionalPartNom = 0; optionalPartNom = 0;
@ -1330,7 +1330,7 @@ void DslDictionary::getArticleText( uint32_t articleAddress, QString & headword,
articleData.clear(); articleData.clear();
ArticleDom dom( gd::normalize( articleText ) ); ArticleDom dom( gd::normalize( articleText ), getName(), articleHeadword );
articleText.clear(); articleText.clear();
@ -1477,7 +1477,7 @@ void DslArticleRequest::run()
if( displayedHeadword.size() == 1 && displayedHeadword[0] == '<' ) // Fix special case - "<" header if( displayedHeadword.size() == 1 && displayedHeadword[0] == '<' ) // Fix special case - "<" header
articleText += "<"; // dslToHtml can't handle it correctly. articleText += "<"; // dslToHtml can't handle it correctly.
else else
articleText += dict.dslToHtml( displayedHeadword ); articleText += dict.dslToHtml( displayedHeadword, displayedHeadword );
/// After this may be expand button will be inserted /// After this may be expand button will be inserted
@ -1490,7 +1490,7 @@ void DslArticleRequest::run()
articleAfter += " dir=\"rtl\""; articleAfter += " dir=\"rtl\"";
articleAfter += ">"; articleAfter += ">";
articleAfter += dict.dslToHtml( articleBody ); articleAfter += dict.dslToHtml( articleBody, displayedHeadword );
articleAfter += "</div>"; articleAfter += "</div>";
articleAfter += "</span>"; articleAfter += "</span>";

View file

@ -8,6 +8,7 @@
#include "gddebug.hh" #include "gddebug.hh"
#include "ufile.hh" #include "ufile.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "utf8.hh"
#include <stdio.h> #include <stdio.h>
#include <wctype.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 ] ) ); 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() ), root( Node::Tag(), wstring(), wstring() ), stringPos( str.c_str() ),
transcriptionCount( 0 ) transcriptionCount( 0 ),
dictionaryName( dictName ),
headword( headword_ )
{ {
list< Node * > stack; // Currently opened tags list< Node * > stack; // Currently opened tags
@ -599,8 +603,13 @@ void ArticleDom::closeTag( wstring const & name,
else else
if ( warn ) if ( warn )
{ {
qWarning() << "Warning: no corresponding opening tag for closing tag" << if( !dictionaryName.empty() )
gd::toQString( name ) << "found."; 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() );
} }
} }

View file

@ -62,7 +62,8 @@ struct ArticleDom
/// Does the parse at construction. Refer to the 'root' member variable /// Does the parse at construction. Refer to the 'root' member variable
/// afterwards. /// afterwards.
ArticleDom( wstring const & ); ArticleDom( wstring const &, string const & dictName = string(),
wstring const & headword_ = wstring() );
/// Root of DOM's tree /// Root of DOM's tree
Node root; Node root;
@ -83,6 +84,10 @@ private:
unsigned transcriptionCount; // >0 = inside a [t] tag unsigned transcriptionCount; // >0 = inside a [t] tag
void nextChar() throw( eot ); 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. /// A adapted version of Iconv which takes Dsl encoding and decodes to wchar.