c++ - Charset used by boost-asio error message -
i using boost-asio , want process correctly error message.
in example, made typo (1278 instead of 127):
boost::system::error_code ec; auto address=boost::asio::ip::address::from_string("1278.0.0.1",ec); if(ec) { const char*text=ec.message().c_str(); //do text encoding ? }
i error message , seems encoded in windows 1252 (i using windows 7). seems encoding os encoding.
however, unable find documentation states fact.
are error message in boost asio encoded os character set ?
after digging boost on system, found included hpp files include ipp file in turn calls os functions. if there error, code of error known @ stage.
the real error message formed when message() function called.
the implementation on windows calls formatmessagea or formatmessagew depending if boost_no_ansi_apis defined:
std::string system_error_category::message( int ev ) const { # ifndef boost_no_ansi_apis lpvoid lpmsgbuf = 0; dword retval = ::formatmessagea( format_message_allocate_buffer | format_message_from_system | format_message_ignore_inserts, null, ev, makelangid(lang_neutral, sublang_default), // default language (lpstr) &lpmsgbuf, 0, null ); detail::local_free_on_destruction lfod(lpmsgbuf); if (retval == 0) return std::string("unknown error"); std::string str( static_cast<lpcstr>(lpmsgbuf) ); # else // wince workaround lpvoid lpmsgbuf = 0; dword retval = ::formatmessagew( format_message_allocate_buffer | format_message_from_system | format_message_ignore_inserts, null, ev, makelangid(lang_neutral, sublang_default), // default language (lpwstr) &lpmsgbuf, 0, null ); detail::local_free_on_destruction lfod(lpmsgbuf); if (retval == 0) return std::string("unknown error"); int num_chars = (wcslen( static_cast<lpcwstr>(lpmsgbuf) ) + 1) * 2; lpstr narrow_buffer = (lpstr)_alloca( num_chars ); if (::widechartomultibyte(cp_acp, 0, static_cast<lpcwstr>(lpmsgbuf), -1, narrow_buffer, num_chars, null, null) == 0) return std::string("unknown error"); std::string str( narrow_buffer ); # endif while ( str.size() && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') ) str.erase( str.size()-1 ); if ( str.size() && str[str.size()-1] == '.' ) { str.erase( str.size()-1 ); } return str; }
if message calls formatmessagew, string narrowed system default windows ansi code page (cp_acp)
in cases on windows result default ansi codepage.
Comments
Post a Comment