basic_string with unsigned short

Discussion in 'C++' started by wolverine, Oct 28, 2006.

  1. wolverine

    wolverine Guest

    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.
    wolverine, Oct 28, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    821
    Kaz Kylheku
    Oct 17, 2006
  2. wolverine
    Replies:
    5
    Views:
    860
    =?iso-8859-1?q?Kirit_S=E6lensminde?=
    Oct 28, 2006
  3. wolverine
    Replies:
    0
    Views:
    342
    wolverine
    Oct 28, 2006
  4. wolverine
    Replies:
    0
    Views:
    391
    wolverine
    Oct 30, 2006
  5. Ioannis Vranos

    unsigned short, short literals

    Ioannis Vranos, Mar 4, 2008, in forum: C Programming
    Replies:
    5
    Views:
    675
    Eric Sosman
    Mar 5, 2008
Loading...

Share This Page