diff --git a/CGIFormattedData.cpp b/CGIFormattedData.cpp index 0257334..98c4342 100644 --- a/CGIFormattedData.cpp +++ b/CGIFormattedData.cpp @@ -6,22 +6,25 @@ namespace coreutils { CGIFormattedData::CGIFormattedData() {} CGIFormattedData::CGIFormattedData(ZString cgiData) { - cgiData.split("&"); - for(int ix = 0; ix < cgiData.getList().size(); ++ix) { - cgiData[ix].split("="); - data[cgiData[ix][0]] = cgiData[ix][1]; - data[cgiData[ix][0]].fromCGI(); + if(cgiData != "") { + cgiData.split("&"); + for(int ix = 0; ix < cgiData.getList().size(); ++ix) { + cgiData[ix].split("="); + data[cgiData[ix][0]] = cgiData[ix][1]; + data[cgiData[ix][0]].fromCGI(); + } } } ZString CGIFormattedData::operator=(ZString cgiData) { - cgiData.split("&"); - for(int ix = 0; ix < cgiData.getList().size(); ++ix) { - cgiData[ix].split("="); - data[cgiData[ix][0]] = cgiData[ix][1]; - data[cgiData[ix][0]].fromCGI(); - } + if(cgiData != "") { + cgiData.split("&"); + for(int ix = 0; ix < cgiData.getList().size(); ++ix) { + cgiData[ix].split("="); + data[cgiData[ix][0]] = cgiData[ix][1]; + data[cgiData[ix][0]].fromCGI(); + } + } return cgiData; - } - + } } diff --git a/MFile.cpp b/MFile.cpp index f35044d..314af2e 100644 --- a/MFile.cpp +++ b/MFile.cpp @@ -3,18 +3,22 @@ #include namespace coreutils { - + MFile::MFile(coreutils::MString fileName) : fileName(fileName) { inFile.open(fileName.c_str()); -// *this << inFile; + *this << inFile; +// inFile >> *this; inFile.close(); } + MFile::~MFile() { + update(); + } + void MFile::update() { outFile.open(fileName.c_str()); outFile << *this; outFile.close(); - } - + } } diff --git a/MFile.h b/MFile.h index fd8e928..25e9384 100644 --- a/MFile.h +++ b/MFile.h @@ -25,7 +25,7 @@ namespace coreutils { std::ifstream inFile; std::ofstream outFile; - void onChange() override; +// void onChange() override; void update(); }; diff --git a/MString.cpp b/MString.cpp index 1c86002..f24c571 100644 --- a/MString.cpp +++ b/MString.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace coreutils { @@ -216,6 +217,13 @@ namespace coreutils { return *this; } + MString &MString::operator<<(std::ifstream &pf) { + std::string line; + while(std::getline(pf, line)) + *this << line << '\n'; + return *this; + } + // MString &operator<<(std::ostream &out) { // *this << out; // } diff --git a/MString.h b/MString.h index 4fa32e9..c2b1ed9 100644 --- a/MString.h +++ b/MString.h @@ -170,6 +170,12 @@ namespace coreutils { /// /// + MString &operator<<(std::ifstream &pf); + + /// + /// + /// + MString &operator<<(std::ostream &out); /// diff --git a/ZString.cpp b/ZString.cpp index cb0fc9e..bc362f2 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -117,11 +117,18 @@ namespace coreutils { } bool ZString::operator!=(const char *valuex) const { - if(strlen(valuex) != length) - return true; - return (strncmp(data, valuex, length) != 0); + if(valuex == NULL) { + if(length == 0) + return false; + else + return true; + } else { + if(strlen(valuex) != length) + return true; + return (strncmp(data, valuex, length) != 0); + } } - + std::vector &ZString::getList() { return list; } diff --git a/testing/compile b/testing/compile index 46de7d7..b305a03 100755 --- a/testing/compile +++ b/testing/compile @@ -2,3 +2,4 @@ g++ -g -std=c++20 -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils g++ -g -std=c++20 -o mstring_test mstring_test.cpp -I.. -L.. -lCoreUtils -lb64 g++ -o jstring_test jstring_test.cpp -I.. -L.. -lCoreUtils +g++ -g -std=c++20 -o mfile_test mfile_test.cpp -I.. -L.. -lCoreUtils diff --git a/testing/json_sample b/testing/json_sample new file mode 100644 index 0000000..e69de29 diff --git a/testing/jstring_test b/testing/jstring_test index fab3eb8..74d88c6 100755 Binary files a/testing/jstring_test and b/testing/jstring_test differ diff --git a/testing/mfile_test b/testing/mfile_test new file mode 100755 index 0000000..e91b3a4 Binary files /dev/null and b/testing/mfile_test differ diff --git a/testing/mfile_test.cpp b/testing/mfile_test.cpp new file mode 100644 index 0000000..f3a9064 --- /dev/null +++ b/testing/mfile_test.cpp @@ -0,0 +1,7 @@ +#include +#include "../MFile.h" +int main(int argc, char **argv) { + coreutils::MFile data("testdata.data"); + std::cout << data << std::endl; + return 0; +} \ No newline at end of file diff --git a/testing/testdata.data b/testing/testdata.data new file mode 100644 index 0000000..c4e2675 --- /dev/null +++ b/testing/testdata.data @@ -0,0 +1,7 @@ +#include +#include "../MFile.h" +int main(int argc, char **argv) { + coreutils::MFile data("testdata.data"); + std::cout << data << std::endl; + return 0; +}