Skip to content

Commit

Permalink
Merge pull request #27 from jespa007/develop
Browse files Browse the repository at this point in the history
Update changes Develop
  • Loading branch information
jespa007 authored Jun 12, 2023
2 parents 3922f20 + dbcb66c commit 0b71cdc
Show file tree
Hide file tree
Showing 31 changed files with 128 additions and 139 deletions.
8 changes: 7 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@


----------------------------
Date: 13/05/2022
Date: 8/06/2023
Version: 2.3.0

- [x] Refactory utils

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

- [x] Change name JsonVarXXXX -> XXXXJsonVar
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ try{

// 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::zj_strutils::int_to_str(i+1);
json_object->plugins[i] = "my_randomstring"+zetjsoncpp::String::integerToString(i+1);
}

// iterate of all interpolations and replace its data values...
Expand Down Expand Up @@ -506,7 +506,7 @@ int main(int argc, char *argv[]){
// 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::zj_strutils::int_to_str(i+1);
json_object->plugins[i] = "my_randomstring"+zetjsoncpp::String::integerToString(i+1);
}
// iterate of all interpolations and replace its data values...
Expand Down
15 changes: 8 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ endif()
set( ZETJSONCPP_LIB_SRCS ${ZETJSONCPP_LIB_SRCS}


util/zj_util.cpp
utils/string_utils.cpp
utils/file_utils.cpp
utils/path_utils.cpp
jsonvar/JsonVar.cpp
jsonvar/ObjectJsonVar.cpp
zetjsoncpp_deserializer.cpp
Expand Down Expand Up @@ -204,10 +206,9 @@ endif()

SET(
HS
util/zj_strutils.h
util/zj_file.h
util/zj_path.h
util/zj_util.h
utils/string_utils.h
utils/file_utils.h
utils/path_utils.h
jsonvar/JsonVar.h
jsonvar/NamedJsonVar.h

Expand All @@ -230,7 +231,7 @@ SET(

zetjsoncpp.h
zetjsoncpp.tcc
exception.h
deserialize_exception.h
)


Expand All @@ -247,7 +248,7 @@ add_executable(test${POST_NAME}
target_link_libraries(test${POST_NAME} ${ZETJSONCPP_LIB_NAME}${POST_NAME})


# Test File
# Test file_utils
add_executable(test_file${POST_NAME}
${JSON_TEST_FILE_SRCS}
)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/jsonvar/BooleanJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace zetjsoncpp{
public:

static bool parse(const std::string & s){
if(zj_strutils::to_lower(s) == "true") return true;
if(zj_strutils::to_lower(s) == "false") return false;
if(string_utils::toLower(s) == "true") return true;
if(string_utils::toLower(s) == "false") return false;

throw ("Cannot parse string to boolean.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/jsonvar/MapBooleanJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace zetjsoncpp{

virtual JsonVar *newJsonVar(const std::string & key_id){
if(this->__zj_map_data__.count(key_id) != 0){
throw std::runtime_error(zj_strutils::format("property name \"%s\" already exists",key_id.c_str()));
throw std::runtime_error(string_utils::format("property name \"%s\" already exists",key_id.c_str()));
}
this->__zj_map_data__[key_id]=BooleanJsonVar<>();

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

virtual JsonVar *newJsonVar(const std::string & key_id){
if(this->__zj_map_data__.count(key_id) != 0){
throw std::runtime_error(zj_strutils::format("property name \"%s\" already exists",key_id.c_str()));
throw std::runtime_error(string_utils::format("property name \"%s\" already exists",key_id.c_str()));
}
this->__zj_map_data__[key_id]=NumberJsonVar<>();

Expand Down
4 changes: 2 additions & 2 deletions src/jsonvar/MapObjectJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace zetjsoncpp{
MapObjectJsonVar() {
init();
}


virtual JsonVar *newJsonVar(const std::string & key_id) {

if(this->__zj_map_data__.count(key_id) != 0){
throw std::runtime_error(zj_strutils::format("property name \"%s\" already exists",key_id.c_str()));
throw std::runtime_error(string_utils::format("property name \"%s\" already exists",key_id.c_str()));
}

ObjectJsonVar< _T_DATA> *tt = new ObjectJsonVar<_T_DATA>;
Expand Down
2 changes: 1 addition & 1 deletion src/jsonvar/MapStringJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace zetjsoncpp{

virtual JsonVar *newJsonVar(const std::string & key_id){
if(this->__zj_map_data__.count(key_id) != 0){
throw std::runtime_error(zj_strutils::format("property name \"%s\" already exists",key_id.c_str()));
throw std::runtime_error(string_utils::format("property name \"%s\" already exists",key_id.c_str()));
}
this->__zj_map_data__[key_id]=StringJsonVar<>();

Expand Down
2 changes: 1 addition & 1 deletion src/jsonvar/NamedJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace zetjsoncpp{
std::string s_aux(vec.begin(), vec.end());
/*if(s_aux.size()>=ZJ_MAX_CONST_CHAR){
throw new std::runtime_error(
"zetjsoncpp::NamedJsonVar: '"+s_aux+"' exceeds character size (max "+zj_strutils::int_to_str(ZJ_MAX_CONST_CHAR)+")"
"zetjsoncpp::NamedJsonVar: '"+s_aux+"' exceeds character size (max "+string_utils::integerToString(ZJ_MAX_CONST_CHAR)+")"
);
}*/
strcpy(this->__zj_variable_name__,s_aux.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/jsonvar/NumberJsonVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace zetjsoncpp{

static float parse(const std::string & str ){
float f=0;
if(zj_strutils::str_to_float(&f,str)!=zj_strutils::STR_2_NUMBER_SUCCESS){
if(string_utils::stringToFloat(&f,str)!=string_utils::STR_2_NUMBER_SUCCESS){
throw std::runtime_error(std::string("cannot convert ") + str + std::string(" as float"));
}

Expand Down
16 changes: 0 additions & 16 deletions src/util/zj_path.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions src/util/zj_path.h

This file was deleted.

34 changes: 0 additions & 34 deletions src/util/zj_strutils.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/util/zj_util.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions src/util/zj_util.h

This file was deleted.

6 changes: 4 additions & 2 deletions src/util/zj_file.cpp → src/utils/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace zetjsoncpp
{
namespace zj_file{

namespace file_utils{

bool exists(const std::string & m_file) {

if (zj_strutils::ends_with(m_file, "/"))
if (string_utils::endsWith(m_file, "/"))
return false;

if (m_file == "")
Expand Down Expand Up @@ -83,5 +84,6 @@ namespace zetjsoncpp

return -1;
}

}
}
3 changes: 1 addition & 2 deletions src/util/zj_file.h → src/utils/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace zetjsoncpp
{
namespace zj_file{
namespace file_utils{
bool exists(const std::string & m_file) ;
char * read(const std::string & filename, bool end_string_char=true);
int length(const std::string & file);
}

}
13 changes: 13 additions & 0 deletions src/utils/path_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "zetjsoncpp.h"

namespace zetjsoncpp
{
std::string path_utils::getFilename(const std::string & _filename) {
size_t found;
std::string ss = _filename;
found = _filename.find_last_of("/\\");
if ((int)found != -1)
ss = _filename.substr(found + 1);
return ss;
}
}
8 changes: 8 additions & 0 deletions src/utils/path_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace zetjsoncpp
{
namespace path_utils{
std::string getFilename(const std::string & _filename);
}
}
16 changes: 8 additions & 8 deletions src/util/zj_strutils.cpp → src/utils/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace zetjsoncpp{

namespace zj_strutils{
namespace string_utils{

std::string format(const char *input_text, ...){
char _sformat_buffer[ZJ_MAX_STR_BUFFER] = { 0 };
Expand All @@ -22,7 +22,7 @@ namespace zetjsoncpp{
return std::string(_sformat_buffer);
}

STR_2_NUMBER str_to_int(int * i, const std::string & s, int base){
STR_2_NUMBER stringToInteger(int * i, const std::string & s, int base){
char *end;
long l;
errno = 0;
Expand All @@ -40,7 +40,7 @@ namespace zetjsoncpp{
return STR_2_NUMBER_SUCCESS;
}

STR_2_NUMBER str_to_float(float * f, const std::string & s){
STR_2_NUMBER stringToFloat(float * f, const std::string & s){
char *end;
char *data=(char *)s.c_str();
float l;
Expand All @@ -62,30 +62,30 @@ namespace zetjsoncpp{
}


std::string int_to_str(int number){
std::string integerToString(int number){

std::stringstream ss;//create a stringstream
ss << number;//add number to the stream
return ss.str();//return a string with the contents of the stream
}

std::string float_to_str(float number){
std::string floatToString(float number){

char buff[100];
sprintf(buff, "%f",number);
std::string ss = buff;
return ss;//return a string with the contents of the stream
}

std::string to_lower(const std::string & str){
std::string toLower(const std::string & str){

std::string ret = str;
for(unsigned short l = 0; l < ret.size();l++)
ret[l] = tolower(ret[l]);
return ret;
}

bool ends_with(const std::string & fullString, const std::string & ending){
bool endsWith(const std::string & fullString, const std::string & ending){
if (fullString.length() >= ending.length()) {
return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
}
Expand All @@ -94,7 +94,7 @@ namespace zetjsoncpp{
}


std::wstring to_wstring_utf8(const std::string & str){
std::wstring toWStringUtf8(const std::string & str){
std::wstring_convert<std::codecvt_utf8<wchar_t>> str_utf8_to_wstring_conv;
return str_utf8_to_wstring_conv.from_bytes(str);
}
Expand Down
31 changes: 31 additions & 0 deletions src/utils/string_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is distributed under the MIT License.
* See LICENSE file for details.
*/
#pragma once

namespace zetjsoncpp {

namespace string_utils{

typedef enum {
STR_2_NUMBER_SUCCESS,
STR_2_NUMBER_OVERFLOW,
STR_2_NUMBER_UNDERFLOW,
STR_2_NUMBER_INCONVERTIBLE
} STR_2_NUMBER;

bool isEmpty(const std::string & str);

std::string format(const char *input_text, ...);
STR_2_NUMBER stringToInteger(int * i, const std::string & s, int base = 0);
STR_2_NUMBER stringToFloat(float * f, const std::string & s);
std::string integerToString(int number);
std::string floatToString(float number);

std::string toLower(const std::string & str);
bool endsWith(const std::string & fullString, const std::string & ending);
std::wstring toWStringUtf8(const std::string & s);
}

}
Loading

0 comments on commit 0b71cdc

Please sign in to comment.