stringをQuotedPrintableにエンコードします。
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
#include <string>
#include <iostream>
const static char* g_cpHex = "0123456789ABCDEF";
/*
QuotedPrintableエンコード
*/
std::string EncodeQuotedPrintable
(
std::string oStr
)
{
std::string oRet;
std::string::iterator ite = oStr.begin();
std::string::iterator iteEnd = oStr.end();
// 全データを巡回
while( ite != iteEnd ) {
// 1データ取得
unsigned char bChar = *ite++;
// 変換
if (0&& '=' != bChar && ( 0x21 <= bChar && 0x7E >= bChar ) ) {
oRet += bChar;
}
else {
oRet += '=';
oRet += g_cpHex[ bChar >> 4 ];
oRet += g_cpHex[ bChar & 0xf ];
}
}
// 結果を返す
return( oRet );
}
int _tmain
(
int argc
, _TCHAR* argv[]
)
{
// 標準出力にユニコード出力する
setlocale( LC_ALL, "Japanese" );
std::string str = "QuotedPrintable";
std::cout << "■変換前" << std::endl;
std::cout << str << std::endl;
std::cout << std::endl;
// stringをstringで置換する
str = EncodeQuotedPrintable( str );
// 標準出力へ出力する
std::cout << "■変換後" << std::endl;
std::cout << str << std::endl;
// 正常終了
return( 0 );
}
■変換前
uotedPrintable
■変換後
=51=75=6F=74=65=64=50=72=69=6E=74=61=62=6C=65