[c++] Address failure in JSON Unicode conversion
Throw a bond::CoreException insteand of a Boost exception when Unicode conversion fails during JSON deserialization to wstring.
This commit is contained in:
Родитель
e90294c562
Коммит
3d67501110
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -15,14 +15,18 @@ different versioning scheme, following the Haskell community's
|
|||
* `gbc` & compiler library: TBD
|
||||
* IDL core version: TBD
|
||||
* IDL comm version: TBD
|
||||
* C++ version: TBD
|
||||
* C++ version: TBD (bug fix bump needed)
|
||||
* C# NuGet version: TBD (bug fix bump needed)
|
||||
* C# Comm NuGet version: TBD
|
||||
|
||||
### C++ ###
|
||||
|
||||
* When Unicode conversion fails during JSON deserialization to wstring, a
|
||||
bond::CoreException is now thrown instead of a Boost exception.
|
||||
|
||||
### C# ###
|
||||
|
||||
* Reflection.IsBonded now recognizes custom IBonded
|
||||
implementations.
|
||||
* Reflection.IsBonded now recognizes custom IBonded implementations.
|
||||
|
||||
## 6.0.0: 2017-06-29 ##
|
||||
* `gbc` & compiler library: 0.10.0.0
|
||||
|
|
|
@ -105,7 +105,14 @@ BOND_NORETURN inline void RapidJsonException(const char* error, size_t offset)
|
|||
"JSON parser error: " << error << " at offset " << offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOND_NORETURN inline void UnicodeConversionException(void)
|
||||
{
|
||||
BOND_THROW(CoreException,
|
||||
"Unicode conversion exception");
|
||||
}
|
||||
|
||||
|
||||
struct StreamException
|
||||
: Exception
|
||||
{
|
||||
|
|
|
@ -279,19 +279,26 @@ template <typename T>
|
|||
typename boost::enable_if<is_wstring<T> >::type
|
||||
Read(const rapidjson::Value& value, T& var)
|
||||
{
|
||||
const std::basic_string<uint16_t> str =
|
||||
boost::locale::conv::utf_to_utf<uint16_t>(
|
||||
value.GetString(),
|
||||
value.GetString() + value.GetStringLength(),
|
||||
boost::locale::conv::stop);
|
||||
try
|
||||
{
|
||||
const std::basic_string<uint16_t> str =
|
||||
boost::locale::conv::utf_to_utf<uint16_t>(
|
||||
value.GetString(),
|
||||
value.GetString() + value.GetStringLength(),
|
||||
boost::locale::conv::stop);
|
||||
|
||||
const size_t length = str.size();
|
||||
resize_string(var, static_cast<uint32_t>(length));
|
||||
const size_t length = str.size();
|
||||
resize_string(var, static_cast<uint32_t>(length));
|
||||
|
||||
std::copy(
|
||||
str.begin(),
|
||||
str.end(),
|
||||
make_checked_array_iterator(string_data(var), length));
|
||||
std::copy(
|
||||
str.begin(),
|
||||
str.end(),
|
||||
make_checked_array_iterator(string_data(var), length));
|
||||
}
|
||||
catch (const boost::locale::conv::conversion_error &)
|
||||
{
|
||||
UnicodeConversionException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче