Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > basic_string with unsigned short

Reply
Thread Tools

basic_string with unsigned short

 
 
wolverine
Guest
Posts: n/a
 
      10-28-2006
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 trying to 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 wstring I cannot use
wstring since wchar_t is 32 bit in linux and XMLCh is 16 bit. So
conversion between 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 short.

Thanks in Advance
Kiran.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
basic_string with unsigned short wolverine C++ 0 10-30-2006 01:50 PM
basic_string with unsigned short wolverine C++ 5 10-28-2006 04:34 PM
basic_string with unsigned short - initialization and usage wolverine C++ 0 10-28-2006 06:06 AM
unsigned short short? slougheed@gmail.com C++ 4 10-16-2006 11:25 PM
Linking error LNK2001 - "__declspec(dllimport) private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Tidy(unsigned short)" (__imp_?_Tidy@?$basic_string@DU?$char_ sharmadeep1980@gmail.com C++ 1 07-07-2006 07:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57