mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
** Big Maps Projects code (incl. Multiplayer v1.5 ** ********************************************************** - Merged Big Maps Project code from BMP+MP trunk (Revision: 3340) o Complete SVN Revision history: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP - Before THIS merge, I made a branch of the existing 1.13 source o SVN Branch: https://81.169.133.124/source/ja2/branches/JA2_rev.3336/src - Removed old VS 6.0 and VS 2003 project and solutions files, because compilation is broken long time ago - I will add VS 2010 projects and solution file in the next few days git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@3341 3b4a5df2-a311-0410-b5c6-a8a6f20db521
134 lines
5.7 KiB
C++
134 lines
5.7 KiB
C++
#ifndef _UTF8STRING_H_
|
|
#define _UTF8STRING_H_
|
|
|
|
#include "vfs_config.h"
|
|
#include <string>
|
|
#include <sstream>
|
|
|
|
// simple UTF8 wrapper, uses utf8 implementation from http://utfcpp.sourceforge.net/
|
|
class VFS_API utf8string
|
|
{
|
|
friend bool operator<(utf8string const& s1, utf8string const& s2);
|
|
friend class StrAccess;
|
|
public:
|
|
typedef std::wstring str_t;
|
|
typedef str_t::value_type char_t;
|
|
typedef str_t::value_type* ptr_t;
|
|
|
|
typedef str_t::size_type size_t;
|
|
////////////////////////////////////////////////////////////////////
|
|
static bool less(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
|
static bool equal(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
|
// case sensitive
|
|
static bool lessCase(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
|
static bool equalCase(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
|
|
|
template<bool (*funName)(const utf8string::char_t* s1, const utf8string::char_t* s2)>
|
|
class Op{
|
|
public:
|
|
bool operator()(const utf8string& s1, const utf8string& s2) const
|
|
{
|
|
return funName(s1.c_str(),s2.c_str());
|
|
}
|
|
};
|
|
typedef Op<utf8string::less> Less;
|
|
typedef Op<utf8string::lessCase> LessCase;
|
|
typedef Op<utf8string::equal> Equal;
|
|
typedef Op<utf8string::equalCase> EqualCase;
|
|
public:
|
|
utf8string();
|
|
utf8string(const char* str);
|
|
utf8string(std::string const& str);
|
|
utf8string(const wchar_t* str);
|
|
utf8string(std::wstring const& str);
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
static utf8string::str_t as_utf16(const char* str);
|
|
static void as_utf16(const char* str, utf8string::str_t &str16);
|
|
static utf8string::str_t as_utf16(std::string const& str);
|
|
static void as_utf16(std::string const& str, utf8string::str_t &str16);
|
|
// fast conversion without creating an internal copy
|
|
static std::string as_utf8(utf8string const& str);
|
|
static std::string as_utf8(std::wstring const& str);
|
|
// if 'strlen' is 0, length is determined automatically
|
|
static std::string as_utf8(const wchar_t* str, utf8string::size_t strlength=0);
|
|
//
|
|
static std::string narrow(wchar_t const* str, utf8string::size_t length);
|
|
static utf8string::size_t narrow(wchar_t const* src_str, utf8string::size_t src_len, char* dst_str, utf8string::size_t dst_len);
|
|
static utf8string::size_t narrow(std::wstring const& src, std::string& dst);
|
|
//
|
|
static std::wstring widen(char const* str, utf8string::size_t length);
|
|
static utf8string::size_t widen(char const* src_str, utf8string::size_t src_len, wchar_t* dst_str, utf8string::size_t dst_len);
|
|
static utf8string::size_t widen(std::string const& src, std::wstring& dst);
|
|
|
|
// convenience method, for the case it should be used in generic code (overloading)
|
|
static std::string as_utf8(std::string const& str);
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// convert string to UTF8 encoding
|
|
inline std::string utf8() const { return as_utf8(_str); }
|
|
|
|
// returns const reference to copy or compare string
|
|
inline std::wstring const& c_wcs() const { return _str; }
|
|
|
|
inline const wchar_t* c_str() const { return _str.c_str(); }
|
|
|
|
// returns reference to modify string
|
|
inline std::wstring& r_wcs() { return _str; }
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
bool empty() const;
|
|
utf8string::size_t length() const;
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
utf8string operator+(utf8string const& str);
|
|
utf8string operator+=(utf8string const& str);
|
|
private:
|
|
str_t _str;
|
|
};
|
|
|
|
bool operator<(utf8string const& s1, utf8string const& s2);
|
|
VFS_API std::wstringstream& operator<<(std::wstringstream& out, utf8string const& str);
|
|
VFS_API std::wstringstream& operator<<(std::wstringstream& out, utf8string::str_t const& str);
|
|
VFS_API std::wstringstream& operator<<(std::wstringstream& out, const utf8string::char_t* str);
|
|
|
|
// explicit compare
|
|
namespace StrCmp
|
|
{
|
|
// case IN-sensitive
|
|
VFS_API bool Equal(const char* s1, const char* s2);
|
|
VFS_API bool Equal(std::string const& s1, std::string const& s2);
|
|
VFS_API bool Equal(std::string const& s1, const char* s2);
|
|
VFS_API bool Equal(const char* s1, std::string const& s2);
|
|
//
|
|
VFS_API bool Equal(const wchar_t* s1, const wchar_t* s2);
|
|
VFS_API bool Equal(std::wstring const& s1, std::wstring const& s2);
|
|
VFS_API bool Equal(std::wstring const& s1, const wchar_t* s2);
|
|
VFS_API bool Equal(const wchar_t* s1, std::wstring const& s2);
|
|
//
|
|
VFS_API bool Equal(utf8string const& s1, utf8string const& s2);
|
|
VFS_API bool Equal(utf8string const& s1, std::wstring const& s2);
|
|
VFS_API bool Equal(std::wstring const& s1, utf8string const& s2);
|
|
VFS_API bool Equal(utf8string const& s1, const wchar_t* s2);
|
|
VFS_API bool Equal(const wchar_t* s1, utf8string const& s2);
|
|
// case Sensitive
|
|
VFS_API bool EqualCase(const char* s1, const char* s2);
|
|
VFS_API bool EqualCase(std::string const& s1, std::string const& s2);
|
|
VFS_API bool EqualCase(std::string const& s1, const char* s2);
|
|
VFS_API bool EqualCase(const char* s1, std::string const& s2);
|
|
//
|
|
VFS_API bool EqualCase(const wchar_t* s1, const wchar_t* s2);
|
|
VFS_API bool EqualCase(std::wstring const& s1, std::wstring const& s2);
|
|
VFS_API bool EqualCase(std::wstring const& s1, const wchar_t* s2);
|
|
VFS_API bool EqualCase(const wchar_t* s1, std::wstring const& s2);
|
|
//
|
|
VFS_API bool EqualCase(utf8string const& s1, utf8string const& s2);
|
|
VFS_API bool EqualCase(utf8string const& s1, std::wstring const& s2);
|
|
VFS_API bool EqualCase(std::wstring const& s1, utf8string const& s2);
|
|
VFS_API bool EqualCase(utf8string const& s1, const wchar_t* s2);
|
|
VFS_API bool EqualCase(const wchar_t* s1, utf8string const& s2);
|
|
}
|
|
|
|
#endif // _UTF8STRING_H_
|