⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmdcodec.cpp

📁 linux下的eva源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    unsigned int sidx = 0;    unsigned int didx = 0;    const char* data = in.data();    const unsigned int len = in.size();    unsigned int out_len = ((len+2)/3)*4;    // Deal with the 76 characters or less per    // line limit specified in RFC 2045 on a    // pre request basis.    insertLFs = (insertLFs && out_len > 76);    if ( insertLFs )      out_len += ((out_len-1)/76);    int count = 0;    out.resize( out_len );    // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion    if ( len > 1 )    {        while (sidx < len-2)        {            if ( insertLFs )            {                if ( count && (count%76) == 0 )                    out.data()[didx++] = '\n';                count += 4;            }            out.data()[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];            out.data()[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |                                       (data[sidx] << 4) & 077];            out.data()[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 |                                       (data[sidx+1] << 2) & 077];            out.data()[didx++] = Base64EncMap[data[sidx+2] & 077];            sidx += 3;        }    }    if (sidx < len)    {        if ( insertLFs && (count > 0) && (count%76) == 0 )           out.data()[didx++] = '\n';        out.data()[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];        if (sidx < len-1)        {            out.data()[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |												(data[sidx] << 4) & 077];            out.data()[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077];        }        else        {            out.data()[didx++] = Base64EncMap[(data[sidx] << 4) & 077];        }    }    // Add padding    while (didx < out.size())    {        out.data()[didx] = '=';        didx++;    }}QCString QCodecs::base64Decode( const QCString& str ){    if ( str.isEmpty() )        return "";    QByteArray in( str.length() );    memcpy( in.data(), str.data(), str.length() );    return base64Decode( in );}QCString QCodecs::base64Decode( const QByteArray& in ){    QByteArray out;    base64Decode( in, out );    return QCString( out.data(), out.size()+1 );}void QCodecs::base64Decode( const QByteArray& in, QByteArray& out ){    out.resize(0);    if ( in.isEmpty() )        return;    unsigned int count = 0;    unsigned int len = in.size(), tail = len;    const char* data = in.data();    // Deal with possible *nix "BEGIN" marker!!    while ( count < len && (data[count] == '\n' || data[count] == '\r' ||            data[count] == '\t' || data[count] == ' ') )        count++;#ifdef _WIN32    if ( strnicmp(data+count, "begin", 5) == 0 )#else	if ( strncasecmp(data+count, "begin", 5) == 0 )#endif    {        count += 5;        while ( count < len && data[count] != '\n' && data[count] != '\r' )            count++;        while ( count < len && (data[count] == '\n' || data[count] == '\r') )            count ++;        data += count;        tail = (len -= count);    }    // Find the tail end of the actual encoded data even if    // there is/are trailing CR and/or LF.    while ( data[tail-1] == '=' || data[tail-1] == '\n' ||            data[tail-1] == '\r' )        if ( data[--tail] != '=' ) len = tail;    unsigned int outIdx = 0;    out.resize( (count=len) );    for (unsigned int idx = 0; idx < count; idx++)    {        // Adhere to RFC 2045 and ignore characters        // that are not part of the encoding table.        unsigned char ch = data[idx];        if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) ||            (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=')        {            out.data()[outIdx++] = Base64DecMap[ch];        }        else        {            len--;            tail--;        }    }    // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl;    // 4-byte to 3-byte conversion    len = (tail>(len/4)) ? tail-(len/4) : 0;    unsigned int sidx = 0, didx = 0;    if ( len > 1 )    {      while (didx < len-2)      {          out.data()[didx] = (((out.at(sidx) << 2) & 255) | ((out.at(sidx+1) >> 4) & 003));          out.data()[didx+1] = (((out.at(sidx+1) << 4) & 255) | ((out.at(sidx+2) >> 2) & 017));          out.data()[didx+2] = (((out.at(sidx+2) << 6) & 255) | (out.at(sidx+3) & 077));          sidx += 4;          didx += 3;      }    }    if (didx < len)        out.data()[didx] = (((out.at(sidx) << 2) & 255) | ((out.at(sidx+1) >> 4) & 003));    if (++didx < len )        out.data()[didx] = (((out.at(sidx+1) << 4) & 255) | ((out.at(sidx+2) >> 2) & 017));    // Resize the output buffer    if ( len == 0 || len < out.size() )      out.resize(len);}QCString QCodecs::uuencode( const QCString& str ){    if ( str.isEmpty() )        return "";    QByteArray in;    in.resize( str.length() );    memcpy( in.data(), str.data(), str.length() );    return uuencode( in );}QCString QCodecs::uuencode( const QByteArray& in ){    QByteArray out;    uuencode( in, out );    return QCString( out.data(), out.size()+1 );}void QCodecs::uuencode( const QByteArray& in, QByteArray& out ){    out.resize( 0 );    if( in.isEmpty() )        return;    unsigned int sidx = 0;    unsigned int didx = 0;    unsigned int line_len = 45;    const char nl[] = "\n";    const char* data = in.data();    const unsigned int nl_len = strlen(nl);    const unsigned int len = in.size();    out.resize( (len+2)/3*4 + ((len+line_len-1)/line_len)*(nl_len+1) );    // split into lines, adding line-length and line terminator    while (sidx+line_len < len)    {        // line length        out.data()[didx++] = UUEncMap[line_len];        // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion        for (unsigned int end = sidx+line_len; sidx < end; sidx += 3)        {            out.data()[didx++] = UUEncMap[(data[sidx] >> 2) & 077];            out.data()[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 |                                   (data[sidx] << 4) & 077];            out.data()[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 |                                (data[sidx+1] << 2) & 077];            out.data()[didx++] = UUEncMap[data[sidx+2] & 077];        }        // line terminator        //for (unsigned int idx=0; idx < nl_len; idx++)        //out[didx++] = nl[idx];        memcpy(out.data()+didx, nl, nl_len);        didx += nl_len;    }    // line length    out.data()[didx++] = UUEncMap[len-sidx];    // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion    while (sidx+2 < len)    {        out.data()[didx++] = UUEncMap[(data[sidx] >> 2) & 077];        out.data()[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 |                               (data[sidx] << 4) & 077];        out.data()[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 |                               (data[sidx+1] << 2) & 077];        out.data()[didx++] = UUEncMap[data[sidx+2] & 077];        sidx += 3;    }    if (sidx < len-1)    {        out.data()[didx++] = UUEncMap[(data[sidx] >> 2) & 077];        out.data()[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 |                               (data[sidx] << 4) & 077];        out.data()[didx++] = UUEncMap[(data[sidx+1] << 2) & 077];        out.data()[didx++] = UUEncMap[0];    }    else if (sidx < len)    {        out.data()[didx++] = UUEncMap[(data[sidx] >> 2) & 077];        out.data()[didx++] = UUEncMap[(data[sidx] << 4) & 077];        out.data()[didx++] = UUEncMap[0];        out.data()[didx++] = UUEncMap[0];    }    // line terminator    memcpy(out.data()+didx, nl, nl_len);    didx += nl_len;    // sanity check    if ( didx != out.size() )        out.resize( 0 );}QCString QCodecs::uudecode( const QCString& str ){    if ( str.isEmpty() )        return "";    QByteArray in;    in.resize( str.length() );    memcpy( in.data(), str.data(), str.length() );    return uudecode( in );}QCString QCodecs::uudecode( const QByteArray& in ){    QByteArray out;    uudecode( in, out );    return QCString( out.data(), out.size()+1 );}void QCodecs::uudecode( const QByteArray& in, QByteArray& out ){    out.resize( 0 );    if( in.isEmpty() )        return;    unsigned int sidx = 0;    unsigned int didx = 0;    unsigned int len = in.size();    unsigned int line_len, end;    const char* data = in.data();    // Deal with *nix "BEGIN"/"END" separators!!    unsigned int count = 0;    while ( count < len && (data[count] == '\n' || data[count] == '\r' ||            data[count] == '\t' || data[count] == ' ') )        count ++;    bool hasLF = false;#ifdef _WIN32    if ( strnicmp( data+count, "begin", 5) == 0 )#else	if ( strncasecmp( data+count, "begin", 5) == 0 )#endif    {        count += 5;        while ( count < len && data[count] != '\n' && data[count] != '\r' )            count ++;        while ( count < len && (data[count] == '\n' || data[count] == '\r') )            count ++;        data += count;        len -= count;        hasLF = true;    }    out.resize( len/4*3 );    while ( sidx < len )    {        // get line length (in number of encoded octets)        line_len = UUDecMap[ (unsigned char) data[sidx++]];        // ascii printable to 0-63 and 4-byte to 3-byte conversion        end = didx+line_len;        char A, B, C, D;        if (end > 2) {          while (didx < end-2)          {             A = UUDecMap[(unsigned char) data[sidx]];             B = UUDecMap[(unsigned char) data[sidx+1]];             C = UUDecMap[(unsigned char) data[sidx+2]];             D = UUDecMap[(unsigned char) data[sidx+3]];             out.data()[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) );             out.data()[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) );             out.data()[didx++] = ( ((C << 6) & 255) | (D & 077) );             sidx += 4;          }        }        if (didx < end)        {            A = UUDecMap[(unsigned char) data[sidx]];            B = UUDecMap[(unsigned char) data[sidx+1]];            out.data()[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) );        }        if (didx < end)        {            B = UUDecMap[(unsigned char) data[sidx+1]];            C = UUDecMap[(unsigned char) data[sidx+2]];            out.data()[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) );        }        // skip padding        while (sidx < len  && data[sidx] != '\n' && data[sidx] != '\r')            sidx++;        // skip end of line        while (sidx < len  && (data[sidx] == '\n' || data[sidx] == '\r'))            sidx++;        // skip the "END" separator when present.#ifdef _WIN32        if ( hasLF && strnicmp( data+sidx, "end", 3) == 0 )#else		if ( hasLF && strncasecmp( data+sidx, "end", 3) == 0 )#endif            break;    }    if ( didx < out.size()  )        out.resize( didx );}/******************************** QMD5 ********************************/QMD5::QMD5(){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -