added: Q encoding in misc: QEncode()
for mails headers encoding git-svn-id: svn://ttmath.org/publicrep/winix/trunk@711 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -952,3 +952,62 @@ static std::string ain;
|
||||
UrlEncode(ain, out, clear_out);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void QEncodeAddChar(wchar_t c, std::string & out)
|
||||
{
|
||||
if( (c>='A' && c<='Z') ||
|
||||
(c>='a' && c<='z') ||
|
||||
(c>='0' && c<='9') )
|
||||
{
|
||||
out += char(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf1[10];
|
||||
char buf2[10];
|
||||
|
||||
size_t len1 = sizeof(buf1) / sizeof(char);
|
||||
size_t len2 = sizeof(buf2) / sizeof(char);
|
||||
size_t len = Ezc::IntToUTF8(int(c), buf1, len1);
|
||||
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
{
|
||||
// make sure that it produces *capital* letters (ABC...)
|
||||
Toa((unsigned long)(unsigned char)buf1[i], buf2, len2, 16);
|
||||
out += '=';
|
||||
out += buf2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
this encoding is used in mails headers
|
||||
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
|
||||
http://www.faqs.org/rfcs/rfc1522.html
|
||||
|
||||
we have:
|
||||
charset = UTF-8
|
||||
encoding = Q
|
||||
|
||||
current limitation:
|
||||
we do not support checking the maximum length:
|
||||
"An encoded-word may not be more than 75 characters long, including
|
||||
charset, encoding, encoded-text, and delimiters."
|
||||
*/
|
||||
void QEncode(const std::wstring & in, std::string & out, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
out.clear();
|
||||
|
||||
out += "=?UTF-8?Q?";
|
||||
|
||||
for(size_t i=0 ; i<in.size() ; ++i)
|
||||
QEncodeAddChar(in[i], out);
|
||||
|
||||
out += "?=";
|
||||
}
|
||||
|
||||
|
@@ -426,5 +426,6 @@ tm Time(time_t par);
|
||||
void UrlEncode(const std::string & in, std::string & out, bool clear_out = true);
|
||||
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out = true);
|
||||
|
||||
void QEncode(const std::wstring & in, std::string & out, bool clear = true);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user