|
发表于 2004-11-21 20:03:15
|
显示全部楼层
那位仁兄帮忙调试一下~!(C++源码)
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
class urlcode
{
private:
std::vector < char >m_inenpear;
std::vector < char >m_outenpear;
std::vector < char >m_indepear;
std::vector < char >m_outdepear;
int toHex (const int &x)
{
return x > 9 ? x + 55 : x + 48;
}
public:
urlcode ()
{
}
~urlcode ()
{
m_inenpear.clear ();
m_outenpear.clear ();
m_indepear.clear ();
m_outdepear.clear ();
}
int encodeTransfer (std::vector < char >&inenpear)
{
m_inenpear = inenpear;
std::vector < char >::iterator pinpear = m_inenpear.begin ();
int tmpinpear;
for (; pinpear != m_inenpear.end (); pinpear++)
{
tmpinpear = *pinpear;
if (((0x40 < tmpinpear) && (tmpinpear < 0x5b))
|| ((0x60 < tmpinpear) && (tmpinpear < 0x7b))
|| ((0x2f < tmpinpear) && (tmpinpear < 0x3a)))
{
m_outenpear.push_back (*pinpear);
}
else
{
if (((0x08 < tmpinpear) && (tmpinpear < 0x0e))
|| (tmpinpear == 0x20))
{
m_outenpear.push_back ('+');
}
else
{
m_outenpear.push_back ('%');
m_outenpear.push_back (toHex (*pinpear >> 4));
m_outenpear.push_back (toHex (*pinpear % 16));
}
}
}
return 0;
}
int decodeTransfer (std::vector < char >&indepear)
{
m_indepear = indepear;
std::vector < char >::iterator pinpear = m_indepear.begin ();
char tmpinpear = 0;;
char outpear = 0x00;
for (; pinpear != m_indepear.end (); pinpear++)
{
tmpinpear = *pinpear;
if (((0x20 < tmpinpear) && (tmpinpear < 0x5b) && (tmpinpear != '%'))
|| ((0x60 < tmpinpear) && (tmpinpear < 0x7b))
|| ((0x2f < tmpinpear) && (tmpinpear < 0x3a)))
{
m_outdepear.push_back (*pinpear);
}
else
{
/**
* (((0x08 < tmpinpear) && (tmpinpear < 0x0e)) || (tmpinpear == 0x20)) -->'+'
*' +' --> 0x20
* it is a limit ; the correct is what? i don't know
*/
if ('+' == tmpinpear)
{
m_outdepear.push_back (0x20);
}
else
{
if ('%' == tmpinpear)
{
tmpinpear = *(++pinpear);
outpear = (tmpinpear - 0x30) << 4;
tmpinpear = *(++pinpear);
if (tmpinpear > 0x40)
tmpinpear = tmpinpear - 0x37;
else
tmpinpear = tmpinpear - 0x30;
outpear += tmpinpear;
m_outdepear.push_back (outpear);
}
}
}
}
return 0;
}
int encodein ()
{
for (int i = 0; (i < m_inenpear.size ()) && (i < 1000); i++)
{
std::cout << m_inenpear;
}
std::cout << std::endl;
return 0;
}
int encodeout ()
{
for (int i = 0; (i < m_outenpear.size ()) && (i < 1000); i++)
{
std::cout << m_outenpear;
}
std::cout << std::endl;
return 0;
}
int decodein ()
{
for (int i = 0; (i < m_indepear.size ()) && (i < 1000); i++)
{
std::cout << m_indepear;
}
std::cout << std::endl;
return 0;
}
int decodeout ()
{
for (int i = 0; (i < m_outdepear.size ()) && (i < 1000); i++)
{
std::cout << m_outdepear;
}
std::cout << std::endl;
return 0;
}
std::vector < char >&getoutpear ()
{
return m_outenpear;
}
}; |
|