I wanna convert from std::string to UTF-8 hexadecimal.
I do not use C++11.
I created a tool for translating texts anywhere.
sf::Http http("http://translate.google.com.br/");
sf::Http::Request request("/translate_a/t", sf::Http::Request::Post);
std::string str_base = "ie=UTF-8&oe=UTF-8&hl=pt-BR&client=t&sc=2&sl=";
string Idiomas[] = { "Portuguese", "Spanish", "English", "Estonian", "Arabic", "Russian", "Japanese", "French", "German", "Italian" };
string Idioms[] = { "pt", "es", "en", "et", "ar", "ru", "ja", "fr", "de", "it"};
std::string PegarClipboard()
{
if (!OpenClipboard(NULL)) return " ";
HANDLE hData = GetClipboardData(CF_TEXT);
if (hData == NULL) return " ";
char * pszText = static_cast<char*>( GlobalLock(hData) );
if (pszText == NULL) return " ";
std::string text( pszText );
GlobalUnlock( hData );
CloseClipboard();
return text;
}
void SetClipboard(std::string txt)
{
OpenClipboard(NULL);
EmptyClipboard();
HGLOBAL hg=GlobalAlloc(GMEM_MOVEABLE,txt.size()+1);
if (!hg){
CloseClipboard();
return;
}
memcpy(GlobalLock(hg),txt.c_str(),txt.size()+1);
GlobalUnlock(hg);
SetClipboardData(CF_TEXT,hg);
CloseClipboard();
GlobalFree(hg);
}
std::string Traduzir(std::string str, unsigned short language1, unsigned short language2)
{
str = str_base+Idioms[language1]+"&tl="+Idioms[language2]+"&q="+str;
request.setField("Content-Language", Idioms[language2]);
request.setBody(str);
sf::Http::Response response = http.sendRequest(request);
if (response.getStatus() == sf::Http::Response::Ok)
{
std::string resposta(response.getBody());
for(unsigned short i=6; i<resposta.size(); i+=1)
{
if (resposta.at(i) == '"')
{
std::string sub = resposta.substr(4, i - 4);
cout <<sub;
return sub;
}
}
}
else
cout<<response.getStatus();
return "Translation error.";
}
This is my almost complete code.