+ utf8 to/from utf16 implementation
Conflicts: include/mapnik/utils.hpp
This commit is contained in:
parent
7a119a5b9e
commit
6e4169d2b9
1 changed files with 88 additions and 59 deletions
|
@ -29,6 +29,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
using boost::mutex;
|
using boost::mutex;
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,22 +91,14 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
template <typename T,
|
template <typename T,
|
||||||
template <typename U> class CreatePolicy=CreateStatic> class MAPNIK_DECL singleton
|
template <typename U> class CreatePolicy=CreateStatic> class MAPNIK_DECL singleton
|
||||||
{
|
{
|
||||||
#else
|
#else
|
||||||
template <typename T,
|
template <typename T,
|
||||||
template <typename U> class CreatePolicy=CreateStatic> class singleton
|
template <typename U> class CreatePolicy=CreateStatic> class singleton
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __SUNPRO_CC
|
|
||||||
/* Sun's C++ compiler will issue the following errors if CreatePolicy<T> is used:
|
|
||||||
Error: A class template name was expected instead of mapnik::CreatePolicy<mapnik::T>
|
|
||||||
Error: A "friend" declaration must specify a class or function.
|
|
||||||
*/
|
|
||||||
friend class CreatePolicy;
|
|
||||||
#else
|
|
||||||
friend class CreatePolicy<T>;
|
friend class CreatePolicy<T>;
|
||||||
static T* pInstance_;
|
static T* pInstance_;
|
||||||
static bool destroyed_;
|
static bool destroyed_;
|
||||||
|
@ -123,12 +117,12 @@ template <typename T,
|
||||||
destroyed_ = true;
|
destroyed_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
static mutex mutex_;
|
static mutex mutex_;
|
||||||
#endif
|
#endif
|
||||||
singleton() {}
|
singleton() {}
|
||||||
public:
|
public:
|
||||||
static T& instance()
|
static T& instance()
|
||||||
{
|
{
|
||||||
if (! pInstance_)
|
if (! pInstance_)
|
||||||
|
@ -154,17 +148,52 @@ public:
|
||||||
}
|
}
|
||||||
return *pInstance_;
|
return *pInstance_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#ifdef MAPNIK_THREADSAFE
|
#ifdef MAPNIK_THREADSAFE
|
||||||
template <typename T,
|
template <typename T,
|
||||||
template <typename U> class CreatePolicy> mutex singleton<T,CreatePolicy>::mutex_;
|
template <typename U> class CreatePolicy> mutex singleton<T,CreatePolicy>::mutex_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename T,
|
template <typename T,
|
||||||
template <typename U> class CreatePolicy> T* singleton<T,CreatePolicy>::pInstance_=0;
|
template <typename U> class CreatePolicy> T* singleton<T,CreatePolicy>::pInstance_=0;
|
||||||
template <typename T,
|
template <typename T,
|
||||||
template <typename U> class CreatePolicy> bool singleton<T,CreatePolicy>::destroyed_=false;
|
template <typename U> class CreatePolicy> bool singleton<T,CreatePolicy>::destroyed_=false;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WINDOWS
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
// UTF8 <--> UTF16 conversion routines
|
||||||
|
|
||||||
|
std::string utf16_to_utf8(std::wstring const& wstr)
|
||||||
|
{
|
||||||
|
std::string str;
|
||||||
|
int size = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, 0, 0, 0, 0);
|
||||||
|
if(size > 0)
|
||||||
|
{
|
||||||
|
std::vector<char> buffer(size);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &buffer[0], size, 0, 0);
|
||||||
|
str.assign(buffer.begin(), buffer.end() - 1);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring utf8_to_utf16 (std::string const& str)
|
||||||
|
{
|
||||||
|
std::wstring wstr;
|
||||||
|
int size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, 0, 0);
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
std::vector<wchar_t> buffer(size);
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &buffer[0], size);
|
||||||
|
wstr.assign(buffer.begin(), buffer.end() - 1);
|
||||||
|
}
|
||||||
|
return wstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _WINDOWS
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MAPNIK_UTILS_HPP
|
#endif // MAPNIK_UTILS_HPP
|
||||||
|
|
Loading…
Reference in a new issue