Fixed MString and MFile.

This commit is contained in:
Brad Arant 2025-12-04 16:40:11 -08:00
parent 11d6f00bfb
commit 829dc1a3c7
12 changed files with 65 additions and 22 deletions

View File

@ -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;
}
}
}

View File

@ -3,18 +3,22 @@
#include <sys/stat.h>
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();
}
}
}

View File

@ -25,7 +25,7 @@ namespace coreutils {
std::ifstream inFile;
std::ofstream outFile;
void onChange() override;
// void onChange() override;
void update();
};

View File

@ -11,6 +11,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <cctype>
#include <fstream>
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;
// }

View File

@ -170,6 +170,12 @@ namespace coreutils {
///
///
MString &operator<<(std::ifstream &pf);
///
///
///
MString &operator<<(std::ostream &out);
///

View File

@ -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> &ZString::getList() {
return list;
}

View File

@ -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

0
testing/json_sample Normal file
View File

Binary file not shown.

BIN
testing/mfile_test Executable file

Binary file not shown.

7
testing/mfile_test.cpp Normal file
View File

@ -0,0 +1,7 @@
#include <iostream>
#include "../MFile.h"
int main(int argc, char **argv) {
coreutils::MFile data("testdata.data");
std::cout << data << std::endl;
return 0;
}

7
testing/testdata.data Normal file
View File

@ -0,0 +1,7 @@
#include <iostream>
#include "../MFile.h"
int main(int argc, char **argv) {
coreutils::MFile data("testdata.data");
std::cout << data << std::endl;
return 0;
}