帮忙Up+Push
http://www.csdn.net/Expert/topic/439/439303.shtm
http://www.csdn.net/Expert/topic/439/439303.shtm
解决方案 »
- ?memdc 怎么显示到
- 怎样在客户端访问,读写服务器端的数据库
- 一张在内存 cdc 中画好的位图有没有 HBITMAP?如何获取?
- 给大家出个小编程题,看谁能做出来,做得最好
- 散分~随便询问有经验的前辈们 这样的一个项目报价多少是合理的(vc+DirectShow)~~感谢,顶就给分
- 比较复杂的图形绘制系统,有点类似画图板,要求结合COM组件完成,各位给点思路,谢谢!
- 目录对话框
- 只要知道acm(音频压缩管理器)的 并能说上一两句的 都有分 我会慢慢分 这是一个acm贴子之最
- 关于vfp编连
- 包含属性页的对话框应用程序
- *** 急! 请问我的程序运行,debug窗口中显示First-chance exception in MainService.exe (KERNEL32.DLL): 0x000006B5: (no name).是什么意思?
- 高分送高手~~~~~~~~~~~~~~~~~~关于软盘安装
{
public:
CTransferDecoder(){};
virtual ~CTransferDecoder(){};
virtual BOOL Decode(const char* input, char* output, int length, int* outLength) = 0;
};class C7bit8bitTranferDecoder:public CTransferDecoder
{
public:
C7bit8bitTranferDecoder(){};
virtual ~C7bit8bitTranferDecoder(){};
virtual BOOL Decode(const char* input, char* output, int length, int* outLength);
};BOOL C7bit8bitTranferDecoder::Decode(const char* input, char* output, int length, int* outLength)
{
int inputLen = strlen(input);
if( length < inputLen + 1 ) // '\n' at end of line become '\r\n'
return FALSE;
memcpy(output, input, inputLen - 1);
memcpy(output + inputLen - 1, "\r\n", 2);
*outLength = inputLen + 1;
return TRUE;
}#define XX 127
/*
* Table for decoding hexadecimal in quoted-printable
*/
static unsigned char index_hex[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,XX,XX, XX,XX,XX,XX,
XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
};
#define HEXCHAR(c) (index_hex[(unsigned char)(c)])/*
* Table for decoding base64
*/
static unsigned char index_64[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,62, XX,XX,XX,63,
52,53,54,55, 56,57,58,59, 60,61,XX,XX, XX,XX,XX,XX,
XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
15,16,17,18, 19,20,21,22, 23,24,25,XX, XX,XX,XX,XX,
XX,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
};
#define CHAR64(c) (index_64[(unsigned char)(c)])class CQPTranferDecoder:public CTransferDecoder
{
public:
CQPTranferDecoder(){};
virtual ~CQPTranferDecoder(){};
virtual BOOL Decode(const char* input, char* output, int length, int* outLength);
};BOOL CQPTranferDecoder::Decode(const char* input, char* output, int length, int* outLength)
{
int inputLen = strlen(input);
if( length < inputLen + 1 ) //'\n' can possiblly become '\r\n'
return FALSE;
*outLength = 0;
int i = 0;
while(i < inputLen )
{
if( input[i] != '=' )
{
if( input[i] == '\n' )
{
memcpy( output + *outLength, "\r\n", 2);
(*outLength) += 2;
i+=2;
}
else
{
output[ (*outLength)++ ] = input[i];
i++;
}
}
else
{
if( input[i+1] == '\n' ) //skip soft line break
{
i += 2;
continue;
}
else //convert hexical number to char
{
if( HEXCHAR(input[i+1]) == XX || HEXCHAR(input[i+2]) == XX )
return FALSE;
output[ (*outLength)++ ] = HEXCHAR(input[i+1])*16 + HEXCHAR(input[i+2]);
i += 3;
}
}
}
return TRUE;
}class CBase64TranferDecoder:public CTransferDecoder
{
public:
CBase64TranferDecoder(){memset(m_szRemain, 0, sizeof(m_szRemain));};
virtual ~CBase64TranferDecoder(){};
virtual BOOL Decode(const char* input, char* output, int length, int* outLength);
private:
char m_szRemain[4];
};BOOL Base64Decode(const char input[4], BYTE output[3], int* pWrite)
{
if( ( CHAR64(input[0]) == XX && input[0] != '=' )
|| ( CHAR64(input[1]) == XX && input[1] != '=' )
|| ( CHAR64(input[2]) == XX && input[2] != '=' )
|| ( CHAR64(input[3]) == XX && input[3] != '=' ) )
return FALSE; memset(output, 0, 3);
output[0] |= CHAR64(input[0])<<2;
output[0] |= CHAR64(input[1])>>4;
output[1] |= CHAR64(input[1])<<4;
output[1] |= CHAR64(input[2])>>2;
output[2] |= CHAR64(input[2])<<6;
output[2] |= CHAR64(input[3]); for(int i=0; i<4 && input[i]!= '='; i++)NULL;
*pWrite = i*6/8;
return TRUE;
}BOOL CBase64TranferDecoder::Decode(const char* input, char* output, int length, int* outLength)
{
//remove extra char such as '\r\n', SPACE, HTAB......
//store pure encoded chars in line with length = inputLen
int i,j, inputLen;
char temp[MAX_EMAIL_LINE], line[MAX_EMAIL_LINE];
sprintf(temp, "%s%s", m_szRemain, input);
memset(m_szRemain, 0, sizeof(m_szRemain));
for(i=j=0; temp[i] != 0; i++)
if( CHAR64(temp[i])!=XX || temp[i]=='=' )
line[j++] = temp[i];
line[j] = 0;
inputLen = j; //judge whether output is large enough to hold decoded chars
if( length < inputLen )
return FALSE; //decoding
i = *outLength = 0;
while( i<inputLen )
{
if( i + 3 < inputLen )
{
int written;
if( Base64Decode(line+i, (BYTE*)output + *outLength, &written) )
{
*outLength += written;
i+=4;
}
else
return FALSE;
}
else //remainder chars less than 4 chars, save it
{
memcpy(m_szRemain, line+i, inputLen - i);
m_szRemain[inputLen-i] = 0;
i = inputLen;
}
}
return TRUE;
}BOOL HeaderQPDecode(const char* input, char* output, int length, int* outLength)
{
int inputLen = strlen(input);
if( length < inputLen + 1 ) //'\n' can possiblly become '\r\n'
return FALSE;
*outLength = 0;
int i = 0;
while(i < inputLen )
{
if( input[i] == '=' )
{
if( input[i+1] == '\n' ) //skip soft line break
{
i += 2;
continue;
}
else //convert hexical number to char
{
if( HEXCHAR(input[i+1]) == XX || HEXCHAR(input[i+2]) == XX )
return FALSE;
output[ (*outLength)++ ] = HEXCHAR(input[i+1])*16 + HEXCHAR(input[i+2]);
i += 3;
}
}
else
{
if( input[i] == '\n' )
{
memcpy( output + *outLength, "\r\n", 2);
(*outLength) += 2;
i+=2;
}
else if( input[i] == '_' )
{
output[ (*outLength)++ ] = ' ';
i++;
}
else
{
output[ (*outLength)++ ] = input[i];
i++;
}
}
}
return TRUE;
}BOOL HeaderDecode(const char* input, char* output, int length)
{
BOOL result = FALSE;
int i, inputLen = strlen(input);
if( memcmp(input, "=?", 2) == 0
&& memcmp(input + inputLen - 2, "?=", 2) == 0 )
{
int questionCount = 0;
for(i=2; i<inputLen-2; i++) if( input[i] == '?' )questionCount++;
if( questionCount >= 2 )
{
char *first = (char*)memchr(input+2, '?', inputLen-4);
char *second = (char*)memchr(first+1, '?', input + inputLen - 2 - ( first + 1 ));
char temp[MAX_EMAIL_HEADER];
memcpy(temp, second+1, input + inputLen - 2 - ( second + 1 ) );
temp[input + inputLen - 2 - ( second + 1 ) ] = 0;
int writeLen;
//quoted-printable decoding
if( memicmp(first+1, "Q", second - first -1) == 0 )
{
if( HeaderQPDecode(temp, output, length, &writeLen) )
{
output[writeLen] = 0;
result = TRUE;
}
}
//base64 decoding
else if( memicmp(first+1, "B", second - first -1) == 0 )
{
CBase64TranferDecoder base64;
if( base64.Decode(temp, output, length, &writeLen) )
{
output[writeLen] = 0;
result = TRUE;
}
}
}
}
return result;
}
CBase64TranferDecoder和CBase64Decoder的区别呢??
这些函数的应用???
To: ilas <[email protected]>
Subject: =?ISO-8859-1?Q?Re: =D0=AD=D2=E9?=
这个前面的ISO-8859-1为字符集??为什莫有这一项
例如:
输入
input = "=?ISO-8859-1?Q?=D5=B2=C3=C8?="
length = sizeof(output Buffer)
则输出为
output = "我们" //只是举了一个例子,返回内容不一定正确