Browse Source

COM-108: Do not use the WC_NO_BEST_FIT_CHARS flag

COM-121
Thomas 2 years ago
parent
commit
9563065b9d
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      utf8_helper.cpp

+ 6
- 4
utf8_helper.cpp View File

@ -30,16 +30,18 @@ namespace pEp {
}
string result;
int size = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS, _wstr_normalized.c_str(), -1, NULL, 0, NULL, NULL);
int size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, _wstr_normalized.c_str(), -1, NULL, 0, NULL, NULL);
assert(size);
if (size) {
char *buf = new char[size];
WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS, _wstr_normalized.c_str(), -1, buf, size, NULL, NULL);
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, _wstr_normalized.c_str(), -1, buf, size, NULL, NULL);
result = buf;
delete[] buf;
}
else
throw out_of_range("input wstring is not valid while converting UTF-16 to UTF-8.");
else {
DWORD error = GetLastError();
throw out_of_range("input wstring is not valid while converting UTF-16 to UTF-8. Error" + error);
}
return result;
}


Loading…
Cancel
Save