Qt quoted Printable 解码

/*!
 * \brief quotedPrintable_decode_return_QString
 * \param inStr
 * \return
 */
inline QString quotedPrintable_decode_return_QString(const QByteArray &inStr)
{
    QTextCodec *tc;
#if defined(Q_OS_WIN)
    tc = QTextCodec::codecForName("GBK");
#elif defined(Q_OS_LINUX)
    tc = QTextCodec::codecForName("UTF-8");
#endif

    QByteArray dst;
    int i = 0;
    char tmp=0;

    while( i <  inStr.size()  ){
        if( '=' == inStr.at(i) && '\r' == inStr.at(i+1) && '\n' == inStr.at(i+2) ){ //!-- 换行符不做处理
            i += 3;
        }else if( '=' == inStr.at(i) ){ //!-- 编码字符
            char ch1 = inStr.at(i+1);
            char ch2 = inStr.at(i+2);
            tmp = ((ch1>'9')?(ch1-'A'+10):(ch1-'0'))*16+((ch2>'9')?(ch2-'A'+10):(ch2-'0'));
            dst+=tmp;
            i += 3;
        }else{ //!-- 非编码字符
            dst += inStr[i];
            i++;
        }
    }

    return tc->toUnicode(dst);
}

你可能感兴趣的:(qt,quoted,Printable)