Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jespa007 committed Feb 9, 2024
2 parents 781a306 + f09cfed commit 72c1e33
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 77 deletions.
48 changes: 30 additions & 18 deletions HISTORY.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,74 @@


----------------------------
Date: 1/11/2023
Date: 2024-02-08
Version: 2.4.4

- [x] Change StringJsonVar::c_str -> StringJsonVar::toConstChar

----------------------------
Date: 2023-11-03
Version: 2.4.3

- [x] Fix compile on MAC

----------------------------
Date: 2023-11-01
Version: 2.4.2

- [x] Fix issue cmake on MAC

----------------------------
Date: 23/10/2023
Date: 2023-10-23
Version: 2.4.1

- [x] Fix warning MapArrayStrings and put working example

----------------------------
Date: 23/10/2023
Date: 2023-10-23
Version: 2.4.0

- [x] Implement MapArrayStrings

----------------------------
Date: 02/08/2023
Date: 2023-08-02
Version: 2.3.3

- [x] deserialize_exception : Save line and description

----------------------------
Date: 02/08/2023
Date: 2023-08-02
Version: 2.3.2

- [x] Change ArrayJsonVarNumber to ArrayNumberJsonVar

----------------------------
Date: 6/07/2023
Date: 2023-07-06
Version: 2.3.1

- [x] Fix include directory for linux

----------------------------
Date: 8/06/2023
Date: 2023-06-08
Version: 2.3.0

- [x] Refactory utils

----------------------------
Date: 13/05/2023
Date: 2023-05-13
Version: 2.2.0

- [x] Change name JsonVarXXXX -> XXXXJsonVar

----------------------------
Date: 21/12/2022
Date: 2022-12-21
Version: 2.1.0

- [x] Do not serialize unserialized fields in objects
- [x] use -WSanitizer=Address in linux if memmgr directory not found

----------------------------
Date: 01/07/2022
Date: 2022-07-01
Version: 2.0.4

- [x] Compile with pedantic
Expand All @@ -65,27 +77,27 @@ Version: 2.0.4
- [x] reorder dirs

----------------------------
Date: 10/07/2021
Date: 2021-07-10
Version: 2.0.3

- [x] Organize files
- [x] Move src dir

----------------------------
Date: 15/04/2021
Date: 2021-04-15
Version: 2.0.2

- [x] Fix bug write exception message when filename is null (whn loads in mmeory)
- [x] Improve error exception

----------------------------
Date: 7/04/2021
Date: 2021-04-07
Version: 2.0.1

- [x] Fix bug crash when cannot parse json value

----------------------------
Date: 14/02/2021
Date: 2021-02-14
Version: 2.0.0

Main features
Expand Down Expand Up @@ -115,7 +127,7 @@ Detail
#18 Pre/Post name all variables associated with JsonVar

----------------------------
Date: 15/05/2018
Date: 2018-05-15
Version: 1.3.0

- [x] Review version history to new format (MAJOR.MINOR.PATCH)
Expand All @@ -125,7 +137,7 @@ Version: 1.3.0
- [x] improve cmake message prints

----------------------------
Date: 10/05/2018
Date: 2018-05-10
Version: 1.2.0

- [x] MSVC Support (v141 Tools or MSVC++ 2015)
Expand All @@ -136,15 +148,15 @@ Version: 1.2.0
- [x] Changed GPL3 license to MIT

----------------------------
Date: 29/08/2015
Date: 2015-08-29
Version: 1.1.0

- [x] Added feature support numbor as cientific notation (i.e 2.1E-10).
- [x] Added feature on detecting property group or property group arrays.
- [x] Fixed carry return line feeds compatible for Windows

----------------------------
Date: 08/08/2014
Date: 2014-08-08
Version: 1.0.0

- [x] First version
88 changes: 44 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,51 +482,51 @@ The following code it shows and example of loading and operating the data that h
```cpp
int main(int argc, char *argv[]){

try{
auto json_object=zetjsoncpp::deserialize_file<ObjectJsonVar<SampleJson>>("sample.json");

// the values before modifications.
std::cout << "---------------------------------------------------" << std::endl;
std::cout << " Before modifications:"<< std::endl;
std::cout << zetjsoncpp::serialize(json_object);

// From here we can operate with loaded data in our program using c++ operators
// put m_use_space to false...
json_object->indent.use_space = false;

// iterate of all plugins and replace with random strings...
for(unsigned i = 0; i < json_object->plugins.size(); i++) {
json_object->plugins[i] = "my_randomstring"+zetjsoncpp::String::integerToString(i+1);
}
try{
auto json_object=zetjsoncpp::deserialize_file<ObjectJsonVar<SampleJson>>("sample.json");
// the values before modifications.
std::cout << "---------------------------------------------------" << std::endl;
std::cout << " Before modifications:"<< std::endl;
std::cout << zetjsoncpp::serialize(json_object);
// From here we can operate with loaded data in our program using c++ operators
// put m_use_space to false...
json_object->indent.use_space = false;
// iterate of all plugins and replace with random strings...
for(unsigned i = 0; i < json_object->plugins.size(); i++) {
json_object->plugins[i] = "my_randomstring"+zetjsoncpp::String::integerToString(i+1);
}

// iterate of all interpolations and replace its data values...
for(auto it_map = json_object->interpolations.begin(); it_map != json_object->interpolations.end(); it_map++) {
for(auto it = it_map->second->data.begin(); it != it_map->second->data.end(); it++) {
*it = rand();
}
}
// iterate of all interpolations and replace its data values...
for(auto it_map = json_object->interpolations.begin(); it_map != json_object->interpolations.end(); it_map++) {
for(auto it = it_map->second->data.begin(); it != it_map->second->data.end(); it++) {
*it = rand();
}
}
// Modification of a map of array of strings...
int k=0;
for(auto it_map_array_strings : json_object->map_array_strings) {
int j=0;
// Modification of a map of array of strings...
int k=0;
for(auto it_map_array_strings : json_object->map_array_strings) {
int j=0;
for(size_t i=0; i < json_object->map_array_strings[it_map_array_strings.first].size(); i++) {
json_object->map_array_strings[it_map_array_strings.first][i]="modified_string_"+std::to_string(k)+"_"+std::to_string(j);
j++;
}
k++;
}

std::cout << "--------------------------------------------------" << std::endl;
std::cout << " After modifications:"<< std::endl;
std::cout << zetjsoncpp::serialize(json_object);

for(size_t i=0; i < json_object->map_array_strings[it_map_array_strings.first].size(); i++) {
json_object->map_array_strings[it_map_array_strings.first][i]="modified_string_"+std::to_string(k)+"_"+std::to_string(j);
j++;
}
k++;
}

std::cout << "--------------------------------------------------" << std::endl;
std::cout << " After modifications:"<< std::endl;
std::cout << zetjsoncpp::serialize(json_object);

// destroy json_object
delete json_object;
}catch(std::exception & ex){
std::cerr << "Error:" << ex.what() << std::endl;
}
// destroy json_object
delete json_object;
}catch(std::exception & ex){
std::cerr << "Error:" << ex.what() << std::endl;
}
}
```
Expand Down Expand Up @@ -568,7 +568,7 @@ After its execution the output shows the serialized json before and after the ch
"code":"zh-CN"
,"general_texts":
{
"general.hello_word":"你好�"
"general.hello_word":"你好�?"
,"general.no":"没有"
,"general.yes":"是"
}
Expand Down Expand Up @@ -637,7 +637,7 @@ After its execution the output shows the serialized json before and after the ch
"code":"zh-CN"
,"general_texts":
{
"general.hello_word":"你好�"
"general.hello_word":"你好�?"
,"general.no":"没有"
,"general.yes":"是"
}
Expand Down
10 changes: 9 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ cmake_minimum_required(VERSION 3.15)

project(zetjsoncpp)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif()

IF( NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE Release )
ENDIF()
Expand Down Expand Up @@ -96,8 +100,12 @@ if(MSVC)

else()

SET( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS -std=gnu++0x -I -Wall -Wextra -pedantic -static-libstdc++ ")
SET( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS -std=gnu++0x -I -Wall -Wextra -pedantic ")

if(NOT MACOSX)
SET( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -static-libstdc++ ")
endif()

if (MINGW)
MESSAGE("-- Plataform: MINGW" )
else()
Expand Down
8 changes: 5 additions & 3 deletions src/deserialize_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
*/
#pragma once

#define ZJ_EXCEPTION_MAX_ERROR_MESSAGE 4096

namespace zetjsoncpp {

class deserialize_exception: public std::exception
{
std::string description;
int line;
std::string file;
char what_msg[4096];
char what_msg[ZJ_EXCEPTION_MAX_ERROR_MESSAGE];
public:

deserialize_exception(const char * _file, int _line, const std::string & _description){
Expand All @@ -22,9 +24,9 @@ namespace zetjsoncpp {

if(_file != NULL && *_file != 0){
file=_file;
sprintf(what_msg,"[file:%s line:%i] %s",_file, _line, (char *)description.c_str());
snprintf(what_msg,ZJ_EXCEPTION_MAX_ERROR_MESSAGE,"[file:%s line:%i] %s",_file, _line, (char *)description.c_str());
}else{
sprintf(what_msg,"[line:%i] %s",_line,(char *)description.c_str());
snprintf(what_msg,ZJ_EXCEPTION_MAX_ERROR_MESSAGE,"[line:%i] %s",_line,(char *)description.c_str());
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/jsonvar/ArrayBooleanJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ namespace zetjsoncpp{
private:
void copy(const std::vector<bool> & v){
this->__zj_vector_data__.clear();
for(auto it=v.begin(); it != v.end();it++){
this->__zj_vector_data__.push_back(*it);
for(size_t i=0;i<v.size();i++){
bool b=v[i];
this->__zj_vector_data__.push_back(b);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/jsonvar/JsonVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace zetjsoncpp {
}

JsonVar *JsonVar::newJsonVar(const std::string & key){
ZJ_UNUSUED_PARAM(key);
throw std::runtime_error("internal error: newJsonVar not implemented");
}

Expand Down
2 changes: 1 addition & 1 deletion src/jsonvar/StringJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace zetjsoncpp{

operator std::string(){return __zj_value__;}

const char *c_str(){
const char *toConstChar(){
return __zj_value__.c_str();
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace zetjsoncpp{
char _sformat_buffer[ZJ_MAX_STR_BUFFER] = { 0 };
va_list ap;
va_start(ap, input_text);
vsprintf(_sformat_buffer, input_text, ap);
vsnprintf(_sformat_buffer, ZJ_MAX_STR_BUFFER, input_text, ap);
va_end(ap);

return std::string(_sformat_buffer);
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace zetjsoncpp{
std::string floatToString(float number){

char buff[100];
sprintf(buff, "%f",number);
snprintf(buff,100, "%f",number);
std::string ss = buff;
return ss;//return a string with the contents of the stream
}
Expand Down
2 changes: 1 addition & 1 deletion src/zetjsoncpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#define ZETJSONCPP_VERSION_MAJOR 2
#define ZETJSONCPP_VERSION_MINOR 4
#define ZETJSONCPP_VERSION_PATCH 2
#define ZETJSONCPP_VERSION_PATCH 4

#ifdef __MEMMANAGER__
#include "memmgr.h"
Expand Down
6 changes: 3 additions & 3 deletions src/zetjsoncpp_deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include "zetjsoncpp.h"

// Util to capture args by ...
#define ZJ_CAPTURE_VARIABLE_ARGS(text_out, text_in)\
#define ZJ_CAPTURE_VARIABLE_ARGS(text_out,text_out_length, text_in)\
{va_list ap;\
va_start(ap, text_in);\
vsprintf(text_out, text_in, ap);\
vsnprintf(text_out, text_out_length, text_in, ap);\
va_end(ap);}


Expand All @@ -24,7 +24,7 @@ namespace zetjsoncpp{
char where[1024]={0};
char text[ZJ_MAX_C_STRING]={0};
char temp_buff[1024]={0};
ZJ_CAPTURE_VARIABLE_ARGS(text, string_text);
ZJ_CAPTURE_VARIABLE_ARGS(text,ZJ_MAX_C_STRING,string_text);
char *aux=(char *)str_current-1;
char captured[100]={0};
std::string filename="";
Expand Down
Loading

0 comments on commit 72c1e33

Please sign in to comment.