janwas
0bb0df5b2c
- remove headers always included from PCH - nommgr.h is only included ifdef REDEFINED_NEW (allows leaving out the mmgr stuff) - in lib/*.cpp, moved the corresponding include file to right behind the PCH (catches headers that aren't compilable by themselves) - byte_order no longer depends on SDL - add debug_level (another means of filtering debug output; needed for thesis) - split posix stuff up into subdirs (lib/posix and sysdep/win/wposix). makes including only some of the modules (e.g. sockets, time) much easier. This was SVN commit r4728.
92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
/*
|
|
A basic_string derivative that works with uint16_t as its underlying char
|
|
type.
|
|
*/
|
|
#ifndef utf16string_H
|
|
#define utf16string_H
|
|
|
|
// On Linux, wchar_t is 32-bit, so define a new version of it.
|
|
// We now use this code on Windows as well, because wchar_t is a
|
|
// native type and distinct from utf16_t.
|
|
#include <string>
|
|
|
|
typedef uint16_t utf16_t;
|
|
typedef std::basic_string<utf16_t> utf16string;
|
|
typedef std::basic_stringstream<utf16_t> utf16stringstream;
|
|
|
|
namespace std {
|
|
template<>
|
|
struct char_traits<utf16_t>
|
|
{
|
|
typedef utf16_t char_type;
|
|
typedef int int_type;
|
|
typedef streampos pos_type;
|
|
typedef streamoff off_type;
|
|
typedef mbstate_t state_type;
|
|
|
|
static void assign(char_type& c1, const char_type& c2)
|
|
{ c1 = c2; }
|
|
|
|
static bool eq(const char_type& c1, const char_type& c2)
|
|
{ return c1 == c2; }
|
|
|
|
static bool lt(const char_type& c1, const char_type& c2)
|
|
{ return c1 < c2; }
|
|
|
|
static int compare(const char_type* s1, const char_type* s2, size_t n)
|
|
{
|
|
return memcmp(s1, s2, n*sizeof(char_type));
|
|
}
|
|
|
|
static size_t length(const char_type* s)
|
|
{
|
|
const char_type* end=s;
|
|
while (*end) end++;
|
|
return end-s;
|
|
}
|
|
|
|
static const char_type* find(const char_type* s, size_t n, const char_type& a)
|
|
{
|
|
const char_type *end = s+n;
|
|
const char_type *res = std::find(s, end, a);
|
|
return (res != end)?res:NULL;
|
|
}
|
|
|
|
static char_type* move(char_type* s1, const char_type* s2, size_t n)
|
|
{
|
|
return (char_type *)memmove(s1, s2, n*sizeof(char_type));
|
|
}
|
|
|
|
static char_type* copy(char_type* s1, const char_type* s2, size_t n)
|
|
{
|
|
return (char_type *)memcpy2(s1, s2, n*sizeof(char_type));
|
|
}
|
|
|
|
static char_type* assign(char_type* s, size_t n, char_type a)
|
|
{
|
|
while (n--)
|
|
{
|
|
s[n]=a;
|
|
}
|
|
return s;
|
|
}
|
|
|
|
static char_type to_char_type(const int_type& c)
|
|
{ return (char_type)c; }
|
|
|
|
static int_type to_int_type(const char_type& c)
|
|
{ return (int_type)c; }
|
|
|
|
static bool eq_int_type(const int_type& c1, const int_type& c2)
|
|
{ return c1 == c2; }
|
|
|
|
static int_type eof()
|
|
{ return -1; }
|
|
|
|
static int_type not_eof(const int_type& c)
|
|
{ return (c == -1) ? 0 : c; }
|
|
};
|
|
}
|
|
|
|
#endif
|