W
wolverine
Hi
I want to know how to use basic_string with unsigned short (I have
mentioned below why i have to do this). Could any tell me some good
references in this topic. I am new to creating a new basic_string
class.
#include <string>
#include<iostream>
using namespace std;
struct unsigned_short_traits
{
typedef unsigned short _E;
typedef _E char_type;
typedef int int_type;
typedef std::streampos pos_type;
typedef std::streamoff off_type;
typedef std::mbstate_t state_type;
static void assign(_E& _X, const _E& _Y)
{_X = _Y; }
static bool eq(const _E& _X, const _E& _Y)
{return (_X == _Y); }
static bool lt(const _E& _X, const _E& _Y)
{return (_X < _Y); }
static int compare(const _E *_U, const _E *_V, size_t _N)
{return (memcmp(_U, _V, _N)); }
static size_t length(const _E *_U)
{return (strlen((const char *)_U)); }
static _E * copy(_E *_U, const _E *_V, size_t _N)
{return ((_E *)memcpy(_U, _V, _N)); }
static const _E * find(const _E *_U, size_t _N, const _E& _C)
{return ((const _E *)memchr(_U, _C, _N)); }
static _E * move(_E *_U, const _E *_V, size_t _N)
{return ((_E *)memmove(_U, _V, _N)); }
static _E * assign(_E *_U, size_t _N, const _E& _C)
{return ((_E *)memset(_U, _C, _N)); }
static _E to_char_type(const int_type& _C)
{return ((_E)_C); }
static int_type to_int_type(const _E& _C)
{return ((int_type)(_C)); }
static bool eq_int_type(const int_type& _X, const int_type& _Y)
{return (_X == _Y); }
static int_type eof()
{return (EOF); }
static int_type not_eof(const int_type& _C)
{return (_C != eof() ? _C : !eof()); }
};
typedef std::basic_string<unsigned short, unsigned_short_traits>
utf16string;
int main()
{
char *a = "abc";
utf16string str(reinterpret_cast<unsigned short*>(a));
cout<<str<<endl;
return 0;
}
REASON TO CREATE THIS utf16string
I am using xerces parser which uses a XMLCh ( typedef unsigned short
XMLCh) as the basic character. Most of xerces functions have XMLCh
pointers as input. But since my application has to be unicode supported
and at the same time i cannot use std::wstring I cannot use
std::wstring since wchar_t is 32 bit in linux and XMLCh is 16 bit. So
conversion between std::wstring and XMLCh will not work. So i thought
of defining basic_string with unsigned short.
I know this group is not for solving issues in c++ isses regarding any
platform (linux). But i am just asking how to use basic_string with
unsigned char.
Thanks in Advance
Kiran.
I want to know how to use basic_string with unsigned short (I have
mentioned below why i have to do this). Could any tell me some good
references in this topic. I am new to creating a new basic_string
class.
#include <string>
#include<iostream>
using namespace std;
struct unsigned_short_traits
{
typedef unsigned short _E;
typedef _E char_type;
typedef int int_type;
typedef std::streampos pos_type;
typedef std::streamoff off_type;
typedef std::mbstate_t state_type;
static void assign(_E& _X, const _E& _Y)
{_X = _Y; }
static bool eq(const _E& _X, const _E& _Y)
{return (_X == _Y); }
static bool lt(const _E& _X, const _E& _Y)
{return (_X < _Y); }
static int compare(const _E *_U, const _E *_V, size_t _N)
{return (memcmp(_U, _V, _N)); }
static size_t length(const _E *_U)
{return (strlen((const char *)_U)); }
static _E * copy(_E *_U, const _E *_V, size_t _N)
{return ((_E *)memcpy(_U, _V, _N)); }
static const _E * find(const _E *_U, size_t _N, const _E& _C)
{return ((const _E *)memchr(_U, _C, _N)); }
static _E * move(_E *_U, const _E *_V, size_t _N)
{return ((_E *)memmove(_U, _V, _N)); }
static _E * assign(_E *_U, size_t _N, const _E& _C)
{return ((_E *)memset(_U, _C, _N)); }
static _E to_char_type(const int_type& _C)
{return ((_E)_C); }
static int_type to_int_type(const _E& _C)
{return ((int_type)(_C)); }
static bool eq_int_type(const int_type& _X, const int_type& _Y)
{return (_X == _Y); }
static int_type eof()
{return (EOF); }
static int_type not_eof(const int_type& _C)
{return (_C != eof() ? _C : !eof()); }
};
typedef std::basic_string<unsigned short, unsigned_short_traits>
utf16string;
int main()
{
char *a = "abc";
utf16string str(reinterpret_cast<unsigned short*>(a));
cout<<str<<endl;
return 0;
}
REASON TO CREATE THIS utf16string
I am using xerces parser which uses a XMLCh ( typedef unsigned short
XMLCh) as the basic character. Most of xerces functions have XMLCh
pointers as input. But since my application has to be unicode supported
and at the same time i cannot use std::wstring I cannot use
std::wstring since wchar_t is 32 bit in linux and XMLCh is 16 bit. So
conversion between std::wstring and XMLCh will not work. So i thought
of defining basic_string with unsigned short.
I know this group is not for solving issues in c++ isses regarding any
platform (linux). But i am just asking how to use basic_string with
unsigned char.
Thanks in Advance
Kiran.