diff --git a/mdictparser.cc b/mdictparser.cc index dee23a45..882bc75f 100644 --- a/mdictparser.cc +++ b/mdictparser.cc @@ -40,6 +40,7 @@ #include "decompress.hh" #include "gddebug.hh" #include "ripemd.hh" +#include "utils.hh" namespace Mdict { @@ -183,8 +184,6 @@ QString MdictParser::toUtf16( const char * fromCode, const char * from, size_t f if ( !fromCode || !from ) return QString(); - - QTextCodec *codec =QTextCodec::codecForName(fromCode); return codec->toUnicode(from,fromSize); } @@ -647,7 +646,7 @@ QString & MdictParser::substituteStylesheet( QString & article, MdictParser::Sty } if( pos ) { - articleNewText += article.mid( pos ); + articleNewText += Utils::rstripnull( article.mid( pos )); article = articleNewText; articleNewText.clear(); } diff --git a/utils.hh b/utils.hh index 299823d5..eb6cd472 100644 --- a/utils.hh +++ b/utils.hh @@ -26,6 +26,22 @@ inline QString rstrip(const QString &str) { return ""; } +/** + * str="abc\r\n\u0000" should be returned as "abc" + * @brief rstripnull + * @param str + * @return + */ +inline QString rstripnull(const QString &str) { + int n = str.size() - 1; + for (; n >= 0; --n) { + if (!str.at(n).isSpace()&&!str.at(n).isNull()) { + return str.left(n + 1); + } + } + return ""; +} + inline bool isExternalLink(QUrl const &url) { return url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "ftp" || url.scheme() == "mailto" ||