added: to misc: UrlEncode which takes PT::TextStreamBase as an argument
added: to misc: QEncode which takes PT::TextStreamBase as an argument added: to Locale: methods: IsKey, Get which takes PT::TextStreamBase as an argument git-svn-id: svn://ttmath.org/publicrep/winix/trunk@860 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#include "misc.h"
|
||||
#include "log.h"
|
||||
#include "templates/templates.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +27,8 @@ namespace misc_private
|
||||
|
||||
std::ifstream get_file_content;
|
||||
std::string get_file_content_ansi;
|
||||
|
||||
PT::WTextStream tmp_qencode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1037,63 +1038,20 @@ void UrlEncode(const std::wstring & in, std::wstring & out, bool 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 = PT::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();
|
||||
using namespace misc_private;
|
||||
|
||||
out += "=?UTF-8?Q?";
|
||||
|
||||
for(size_t i=0 ; i<in.size() ; ++i)
|
||||
QEncodeAddChar(in[i], out);
|
||||
|
||||
out += "?=";
|
||||
tmp_qencode.clear();
|
||||
QEncode(in, tmp_qencode);
|
||||
tmp_qencode.to_string(out, clear);
|
||||
tmp_qencode.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
deleting all post temporary files
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user