nana::charset
Description
An intelligent charset class for character code conversion.
Model
of
None
Public base classes
None
Members
charset(const charset&) |
The copy construction. |
charset & operator=(const charset&) |
The assignment operator. |
charset(const std::string&) |
Attempt to convert a multibytes string. |
charset(const std::wstring&) |
Attempt to convert a UCS2/UCS4 string. |
~charset() |
The destructor. |
operator std::string() const |
Converts the string to multibytes string. |
operator std::wstring() const |
Converts the string to UCS2/UCS4 string. |
C++03 Members
charset(const std::string&, nana::unicode::t) |
Attempt to convert a unicode string in byte sequence. |
std::string to_bytes(nana::unicode::t) |
Converts the string to a unicode in bytes sequence with a specified unicode transformation format. |
C++11 Members
charset(charset&&) |
The move construction. |
charset & operator=(const charset&&) |
The move assignment operator. |
charset(std::string&&) |
Attempt to convert a multibytes string. |
charset(const std::string&, nana::unicode) |
Attempt to convert a unicode string in byte sequence. |
charset(std::string&&, nana::unicode) |
Ditto. |
charset(const std::wstring&&) |
Attempt to convert a UCS2/UCS4 string. |
operator std::string&&() |
Converts the string to multibytes string. |
operator std::wstring&&() |
Converts the string to UCS2/UCS4 string. |
std::string to_bytes(nana::unicode) |
Converts the string to a unicode in bytes sequenece width a specified unicode transformation format. |
File
nana/charset.hpp
Notes
None.
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);
See also
None.
Move to The Nana Programmer's Guide Main Page |