Nana C++ Library. Reference for users.
What we need to use nana
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
nana::charset Class Reference

An intelligent charset class for character code conversion. Example: More...

Public Member Functions

 charset (const charset &)
 
charsetoperator= (const charset &)
 
 charset (charset &&)
 
charsetoperator= (charset &&)
 
 charset (const std::string &)
 Attempt to convert a multibytes string. More...
 
 charset (std::string &&)
 Attempt to convert a multibytes string. More...
 
 charset (const std::string &, unicode)
 Attempt to convert a unicode string in byte sequence. More...
 
 charset (std::string &&, unicode)
 Attempt to convert a unicode string in byte sequence. More...
 
 charset (const std::wstring &)
 Attempt to convert a UCS2/UCS4 string. More...
 
 charset (std::wstring &&)
 Attempt to convert a UCS2/UCS4 string. More...
 
 ~charset ()
 
 operator std::string () const
 Converts the string to multibytes string. More...
 
 operator std::string && ()
 Converts the string to multibytes string. More...
 
 operator std::wstring () const
 Converts the string to UCS2/UCS4 string. More...
 
 operator std::wstring && ()
 Converts the string to UCS2/UCS4 string. More...
 
std::string to_bytes (unicode) const
 Converts the string to a unicode in bytes sequenece width a specified unicode transformation format. More...
 

Detailed Description

An intelligent charset class for character code conversion. Example:

    1. A UTF-8 string from the socket.

        int len = ::recv(sd, buf, buflen, 0);
        textbox.caption(nana::charset(std::string(buf, len), nana::unicode::utf8));

    2. Send the string in text to the socket as UTF-8.

        std::string utf8str = nana::charset(textbox.caption()).to_bytes(nana::unicode::utf8);
        ::send(sd, utf8str.c_str(), utf8str.size(), 0);

    3, Convert a string to the specified multi-byte character code.

Convert to a multibytes string through default system language. std::string mbstr = nana::charset(a_wstring);

If the default system language is English and convert a Chinese unicode string to multibytes string through GB2312 std::setlocale(LC_CTYPE, "zh_CN.GB2312"); set::setlocale(LC_CTYPE, ".936"); call it in Windows std::string mbstr = nana::charset(a_wstring_with_chinese);

Examples:
widget_show.cpp, and widget_show2.cpp.

Constructor & Destructor Documentation

nana::charset::charset ( const charset rhs)
nana::charset::charset ( charset &&  r)
nana::charset::charset ( const std::string s)

Attempt to convert a multibytes string.

nana::charset::charset ( std::string &&  s)

Attempt to convert a multibytes string.

nana::charset::charset ( const std::string s,
unicode  encoding 
)

Attempt to convert a unicode string in byte sequence.

nana::charset::charset ( std::string &&  s,
unicode  encoding 
)

Attempt to convert a unicode string in byte sequence.

nana::charset::charset ( const std::wstring s)

Attempt to convert a UCS2/UCS4 string.

nana::charset::charset ( std::wstring &&  s)

Attempt to convert a UCS2/UCS4 string.

nana::charset::~charset ( )

Member Function Documentation

nana::charset::operator std::string ( ) const

Converts the string to multibytes string.

nana::charset::operator std::string && ( )

Converts the string to multibytes string.

nana::charset::operator std::wstring ( ) const

Converts the string to UCS2/UCS4 string.

nana::charset::operator std::wstring && ( )

Converts the string to UCS2/UCS4 string.

charset & nana::charset::operator= ( const charset rhs)
charset & nana::charset::operator= ( charset &&  r)
std::string nana::charset::to_bytes ( unicode  encoding) const

Converts the string to a unicode in bytes sequenece width a specified unicode transformation format.