SimpCfg: Trap conversion error and raise appropriate exception
This commit is contained in:
parent
4f5add68c6
commit
cdd91f5ad1
2 changed files with 7 additions and 1 deletions
|
@ -73,6 +73,9 @@ inline size_t wcs_to_mbs(std::string &sDest, const std::wstring &wSrc) {
|
|||
std::mbstate_t mbState = std::mbstate_t();
|
||||
const wchar_t *wSrcP = wSrc.c_str();
|
||||
auto reqLen = std::wcsrtombs(nullptr, &wSrcP, 0, &mbState);
|
||||
if (reqLen == static_cast<std::size_t>(-1)) {
|
||||
throw std::runtime_error("ERRR:WCS2MBS:Failed probing of size...");
|
||||
}
|
||||
sDest.resize(reqLen);
|
||||
return std::wcsrtombs(sDest.data(), &wSrcP, sDest.length(), &mbState);
|
||||
}
|
||||
|
@ -81,6 +84,9 @@ inline size_t mbs_to_wcs(std::wstring &wDest, const std::string &sSrc) {
|
|||
std::mbstate_t mbState = std::mbstate_t();
|
||||
const char *sSrcP = sSrc.c_str();
|
||||
auto reqLen = std::mbsrtowcs(nullptr, &sSrcP, 0, &mbState);
|
||||
if (reqLen == static_cast<std::size_t>(-1)) {
|
||||
throw std::runtime_error("ERRR:MBS2WCS:Failed probing of size...");
|
||||
}
|
||||
wDest.resize(reqLen);
|
||||
return std::mbsrtowcs(wDest.data(), &sSrcP, wDest.length(), &mbState);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ static void check_strings() {
|
|||
SimpCfg::locale_prepare(sSavedLocale);
|
||||
check_string();
|
||||
check_u8string();
|
||||
//check_wstring_wcout();
|
||||
check_wstring_wcout();
|
||||
check_wstring_cout();
|
||||
check_nonenglish();
|
||||
SimpCfg::locale_restore(sSavedLocale);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue