#include <FWebJsonJsonObject.h>
#include <FWebJsonJsonParser.h>
#include <FWebJsonJsonString.h>
+#include <FBase_LocalizedNumParser.h>
#include <FBase_StringConverter.h>
#include "FWebJson_JsonParserImpl.h"
#include "FWebJson_JsonUtils.h"
SysTryReturn(NID_WEB_JSON, created, null, E_INVALID_DATA, "[E_INVALID_DATA] Input data malformed [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
- std::unique_ptr<char[]> pNumber(Tizen::Base::_StringConverter::CopyToCharArrayN(numString));
- SysTryReturn(NID_WEB_JSON, pNumber.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
- double number = atof(pNumber.get());
+ double number = _LocalizedNumParser::ToDouble(numString, "C");
JsonNumber* pJsonNumber = new (std::nothrow) JsonNumber(number);
SysTryReturn(NID_WEB_JSON, pJsonNumber, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
static const char ARRAY_END = ']';
+static const int DBL_MAX_LENGTH = 17 + 308 + 3; // significant decimal digits + exponent + extra characters
+
+
result
_JsonWriterImpl::Compose(const IJsonValue* pValue, String& filePath)
{
case JSON_TYPE_NUMBER:
{
- String out;
- double val1 = static_cast<JsonNumber*>(pValue)->ToDouble();
- double val2 = Math::Floor(val1);
-
- r = (Double::Compare(val1, val2) == 0) ? out.Format(15, L"%g", val1) : out.Format(15, L"%f", val1);
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+ String numString;
+ r = JsonNumberToString(static_cast<JsonNumber*>(pValue)->ToDouble(), numString);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating. numberString is [%ls]", GetErrorMessage(r), numString.GetPointer());
- outString.Append(out);
+ outString.Append(numString);
}
break;
escString.Append(L"\\t");
break;
default:
- if (unEscUnicode || pUnEscBuf[i] < 0x80)
+ if (pUnEscBuf[i] >= 0 && pUnEscBuf[i] < 0x20)
+ {
+ String control;
+ control.Format(7, L"\\u%04x", pUnEscBuf[i]);
+ escString.Append(control);
+ }
+ else if (unEscUnicode || pUnEscBuf[i] < 0x80)
{
escString.Append(pUnEscBuf[i]);
}
}
+result
+_JsonWriterImpl::JsonNumberToString(double value, String& numString)
+{
+ ClearLastResult();
+
+ if (Double::IsNaN(value))
+ {
+ numString = String(L"NaN");
+ return E_INVALID_DATA;
+ }
+
+ if (Double::IsInfinity(value))
+ {
+ numString = String(L"Infinity");
+ return E_INVALID_DATA;
+ }
+
+ wchar_t sValue[DBL_MAX_LENGTH + 1] = {0, };
+ swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%.16lg", value);
+
+ numString = String(sValue);
+ return E_SUCCESS;
+}
+
+
}}} // Tizen::Web::Json