mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Strings unify
This commit is contained in:
@ -66,16 +66,13 @@ namespace NSJSON
|
||||
static_cast<CPrimitive*>(m_internal->m_value.get())->isDouble());
|
||||
}
|
||||
|
||||
bool IValue::IsStringA() const
|
||||
bool IValue::IsString() const
|
||||
{
|
||||
return (m_internal->m_type == CTypedValue::vtPrimitive &&
|
||||
static_cast<CPrimitive*>(m_internal->m_value.get())->isStringA());
|
||||
}
|
||||
if (m_internal->m_type != CTypedValue::vtPrimitive)
|
||||
return false;
|
||||
|
||||
bool IValue::IsStringW() const
|
||||
{
|
||||
return (m_internal->m_type == CTypedValue::vtPrimitive &&
|
||||
static_cast<CPrimitive*>(m_internal->m_value.get())->isStringW());
|
||||
CPrimitive* pPrimitive = static_cast<CPrimitive*>(m_internal->m_value.get());
|
||||
return (pPrimitive->isStringA() || pPrimitive->isStringW());
|
||||
}
|
||||
|
||||
bool IValue::IsArray() const
|
||||
|
||||
@ -73,11 +73,7 @@ namespace NSJSON
|
||||
/**
|
||||
* Returns true if the value is a string.
|
||||
*/
|
||||
bool IsStringA() const;
|
||||
/**
|
||||
* Returns true if the value is a wstring.
|
||||
*/
|
||||
bool IsStringW() const;
|
||||
bool IsString() const;
|
||||
/**
|
||||
* Returns true if the value is an array.
|
||||
*/
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
#include "json_values.h"
|
||||
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
|
||||
namespace NSJSON
|
||||
{
|
||||
IBaseValue::IBaseValue()
|
||||
@ -113,6 +116,13 @@ namespace NSJSON
|
||||
{
|
||||
if (m_type == ptStringA)
|
||||
return m_string;
|
||||
|
||||
if (m_type == ptStringW)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return std::string(converter.to_bytes(m_wstring));
|
||||
}
|
||||
|
||||
#ifdef JSON_DEBUG
|
||||
throw std::bad_cast();
|
||||
#endif
|
||||
@ -123,6 +133,13 @@ namespace NSJSON
|
||||
{
|
||||
if (m_type == ptStringW)
|
||||
return m_wstring;
|
||||
|
||||
if (m_type == ptStringA)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return std::wstring(converter.from_bytes(m_string));
|
||||
}
|
||||
|
||||
#ifdef JSON_DEBUG
|
||||
throw std::bad_cast();
|
||||
#endif
|
||||
|
||||
@ -29,13 +29,9 @@ namespace NSJSON
|
||||
{
|
||||
ret = NSJSBase::CJSContext::createDouble((double)value);
|
||||
}
|
||||
else if (value.IsStringA())
|
||||
else if (value.IsString())
|
||||
{
|
||||
ret = NSJSBase::CJSContext::createString((std::string)value);
|
||||
}
|
||||
else if (value.IsStringW())
|
||||
{
|
||||
ret = NSJSBase::CJSContext::createString((std::wstring)value);
|
||||
ret = NSJSBase::CJSContext::createString(value.ToStringA());
|
||||
}
|
||||
// arrays
|
||||
else if (value.IsArray())
|
||||
|
||||
Reference in New Issue
Block a user