0

My program needs a lot of ANSI<=>UNICODE conversation so I got the idea to create multitype object which will convert all stuff easier than addinational function and a lot of new/delete. Pseudocode:

class CWchar // char based
{
public:
    public static implicit operator wchar_t*(CWchar cw)
    {
        // converting cw.data to wchar_t
        // up to U+FFFF conversion needed
    }
    public static implicit operator char*(CWchar cw)
    {
        return cw.data;
    }
    CWchar& CWchar::operator=(const char* c)
    {
        data = *c; 
        return *this;
    }
    CWchar& CWchar::operator=(const wchar_t* c)
    {
        //conversion to char* ...
        return *this;
    }

    // add some smart pointers, garbage collector, and leave delete

private:
    char* data;
}

Is that really worth coding or should I think about another solution? Maybe there is already done project? Or maybe I am wrong and this idea is bad? Thanks

user1112008
  • 432
  • 10
  • 27
  • 3
    Why do you need to do so much conversion? Is it possible to have just one bridge which interfaces the Unicode side with the non-Unicode side? – Mike Kwan Apr 16 '12 at 12:42
  • My application is mini IM, it receives multibyte char* and I need to convert it to wide wchar_t* so for example greek alphabet would be formatted good. – user1112008 Apr 16 '12 at 12:51
  • @MikeKwan I forgot to add notification, could You say something more about bridge idea? – user1112008 Apr 16 '12 at 13:23

1 Answers1

1

This sounds a lot like codecvt. This allows you to convert between Char* and multibyte wchar_t* streams. This is part of the standard library. The third edition of The C++ Programming Language by Stroustrup has a nice appendix on this.

emsr
  • 15,539
  • 6
  • 49
  • 62