From 666605419cfab90d858f5687659a10e28146d97e Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 13 Nov 2013 21:52:12 +0100 Subject: [PATCH] [DEV] correction of stl-port --- ejson/Number.cpp | 12 +++++++++--- ejson/test.cpp | 10 +++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ejson/Number.cpp b/ejson/Number.cpp index 35a2d4d..ade6ca6 100644 --- a/ejson/Number.cpp +++ b/ejson/Number.cpp @@ -20,14 +20,14 @@ bool ejson::Number::iParse(const std::string& _data, int32_t& _pos, ejson::fileP for (int32_t iii=_pos; iii<_data.size(); iii++) { _filePos.check(_data[iii]); #ifdef ENABLE_DISPLAY_PARSED_ELEMENT - drawElementParsed(_data[iii], _filePos); + drawElementParsed(_data[iii], _filePos); #endif if(true == checkNumber(_data[iii])) { tmpVal+=_data[iii]; } else { _pos = iii-1; m_value = std::stod(tmpVal); - JSON_PARSE_ELEMENT("end parse : 'Number' "); + JSON_PARSE_ELEMENT("end parse : 'Number' " << tmpVal << " >> " << m_value); return true; } } @@ -38,7 +38,13 @@ bool ejson::Number::iParse(const std::string& _data, int32_t& _pos, ejson::fileP bool ejson::Number::iGenerate(std::string& _data, int32_t _indent) const { - _data += m_value; + // special thing to remove .000000 at the end of perfect number ... + int64_t tmpVal = m_value; + if ((double)tmpVal == m_value) { + _data += std::to_string(tmpVal); + } else { + _data += std::to_string(m_value); + } return true; } diff --git a/ejson/test.cpp b/ejson/test.cpp index 17c33a9..9dc4dad 100644 --- a/ejson/test.cpp +++ b/ejson/test.cpp @@ -137,7 +137,7 @@ void init(void) { "{tmpElement:-956256}\n"); l_list.push_back(check); // ------------------------------------------------------ - check.set("{\n\t\"tmpElement\": -956.256\n}\n", + check.set("{\n\t\"tmpElement\": -956.256000\n}\n", -1, "{tmpElement:-956.256}\n"); l_list.push_back(check); @@ -518,8 +518,8 @@ int main(int argc, const char *argv[]) { JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Result in error (normal case)"); } else { JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } different output"); - std::vector tmpout = out.split('\n'); - std::vector tmpref = l_list[iii].m_ref.split('\n'); + std::vector tmpout = string_split(out, '\n'); + std::vector tmpref = string_split(l_list[iii].m_ref, '\n'); //JSON_ERROR("generate : \n" << out); //JSON_ERROR("reference : \n" << l_list[iii].m_ref); for (int32_t jjj=0; jjj tmpout = out.split('\n'); - std::vector tmpref = l_list[iii].m_ref.split('\n'); + std::vector tmpout = string_split(out, '\n'); + std::vector tmpref = string_split(l_list[iii].m_ref, '\n'); //JSON_ERROR("generate : \n" << out); //JSON_ERROR("reference : \n" << l_list[iii].m_ref); for (int32_t jjj=0; jjj