Changeset - 31fb1af807d3
[Not reviewed]
0 3 0
HanzZ - 13 years ago 2012-09-05 18:06:33
hanzz.k@gmail.com
include utils.h
3 files changed with 36 insertions and 3 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/purple_defs.cpp
Show inline comments
 
#include "purple_defs.h"
 
#include "transport/util.h"
 

	
 
using namespace Transport::Util;
 
#include "utils.h"
 

	
 
#if PURPLE_RUNTIME
 

	
backends/libpurple/utils.cpp
Show inline comments
 
@@ -156,3 +156,34 @@ int create_socket(const char *host, int portno) {
 
// 	fcntl(main_socket, F_SETFL, flags);
 
	return main_socket;
 
}
 

	
 
#ifdef _WIN32
 
std::wstring utf8ToUtf16(const std::string& str)
 
{
 
	try
 
	{
 
		if (str.empty())
 
			return L"";
 

	
 
		// First request the size of the required UTF-16 buffer
 
		int numRequiredBytes = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), boost::numeric_cast<int>(str.size()), NULL, 0);
 
		if (!numRequiredBytes)
 
			return L"";
 

	
 
		// Allocate memory for the UTF-16 string
 
		std::vector<wchar_t> utf16Str(numRequiredBytes);
 

	
 
		int numConverted = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), boost::numeric_cast<int>(str.size()), &utf16Str[0], numRequiredBytes);
 
		if (!numConverted)
 
			return L"";
 

	
 
		std::wstring wstr(&utf16Str[0], numConverted);
 
		return wstr;
 
	}
 
	catch (...)
 
	{
 
		// I don't believe libtransport is exception-safe so we'll just return an empty string instead
 
		return L"";
 
	}
 
}
 
#endif // _WIN32
backends/libpurple/utils.h
Show inline comments
 
@@ -31,3 +31,7 @@ int create_socket(const char *host, int portno);
 
GHashTable *spectrum_ui_get_info(void);
 

	
 
void execute_purple_plugin_action(PurpleConnection *gc, const std::string &name);
 

	
 
#ifdef _WIN32
 
	std::wstring utf8ToUtf16(const std::string& str);
 
#endif
0 comments (0 inline, 0 general)