Fixed MString and MFile.
This commit is contained in:
parent
11d6f00bfb
commit
829dc1a3c7
@ -6,6 +6,7 @@ namespace coreutils {
|
|||||||
CGIFormattedData::CGIFormattedData() {}
|
CGIFormattedData::CGIFormattedData() {}
|
||||||
|
|
||||||
CGIFormattedData::CGIFormattedData(ZString cgiData) {
|
CGIFormattedData::CGIFormattedData(ZString cgiData) {
|
||||||
|
if(cgiData != "") {
|
||||||
cgiData.split("&");
|
cgiData.split("&");
|
||||||
for(int ix = 0; ix < cgiData.getList().size(); ++ix) {
|
for(int ix = 0; ix < cgiData.getList().size(); ++ix) {
|
||||||
cgiData[ix].split("=");
|
cgiData[ix].split("=");
|
||||||
@ -13,15 +14,17 @@ namespace coreutils {
|
|||||||
data[cgiData[ix][0]].fromCGI();
|
data[cgiData[ix][0]].fromCGI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ZString CGIFormattedData::operator=(ZString cgiData) {
|
ZString CGIFormattedData::operator=(ZString cgiData) {
|
||||||
|
if(cgiData != "") {
|
||||||
cgiData.split("&");
|
cgiData.split("&");
|
||||||
for(int ix = 0; ix < cgiData.getList().size(); ++ix) {
|
for(int ix = 0; ix < cgiData.getList().size(); ++ix) {
|
||||||
cgiData[ix].split("=");
|
cgiData[ix].split("=");
|
||||||
data[cgiData[ix][0]] = cgiData[ix][1];
|
data[cgiData[ix][0]] = cgiData[ix][1];
|
||||||
data[cgiData[ix][0]].fromCGI();
|
data[cgiData[ix][0]].fromCGI();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return cgiData;
|
return cgiData;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,15 +6,19 @@ namespace coreutils {
|
|||||||
|
|
||||||
MFile::MFile(coreutils::MString fileName) : fileName(fileName) {
|
MFile::MFile(coreutils::MString fileName) : fileName(fileName) {
|
||||||
inFile.open(fileName.c_str());
|
inFile.open(fileName.c_str());
|
||||||
// *this << inFile;
|
*this << inFile;
|
||||||
|
// inFile >> *this;
|
||||||
inFile.close();
|
inFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MFile::~MFile() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void MFile::update() {
|
void MFile::update() {
|
||||||
outFile.open(fileName.c_str());
|
outFile.open(fileName.c_str());
|
||||||
outFile << *this;
|
outFile << *this;
|
||||||
outFile.close();
|
outFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
MFile.h
2
MFile.h
@ -25,7 +25,7 @@ namespace coreutils {
|
|||||||
std::ifstream inFile;
|
std::ifstream inFile;
|
||||||
std::ofstream outFile;
|
std::ofstream outFile;
|
||||||
|
|
||||||
void onChange() override;
|
// void onChange() override;
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
@ -216,6 +217,13 @@ namespace coreutils {
|
|||||||
return *this;
|
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) {
|
// MString &operator<<(std::ostream &out) {
|
||||||
// *this << out;
|
// *this << out;
|
||||||
// }
|
// }
|
||||||
|
|||||||
@ -170,6 +170,12 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
|
MString &operator<<(std::ifstream &pf);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
MString &operator<<(std::ostream &out);
|
MString &operator<<(std::ostream &out);
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|||||||
@ -117,10 +117,17 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::operator!=(const char *valuex) const {
|
bool ZString::operator!=(const char *valuex) const {
|
||||||
|
if(valuex == NULL) {
|
||||||
|
if(length == 0)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
if(strlen(valuex) != length)
|
if(strlen(valuex) != length)
|
||||||
return true;
|
return true;
|
||||||
return (strncmp(data, valuex, length) != 0);
|
return (strncmp(data, valuex, length) != 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ZString> &ZString::getList() {
|
std::vector<ZString> &ZString::getList() {
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@ -2,3 +2,4 @@
|
|||||||
g++ -g -std=c++20 -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils
|
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++ -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++ -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
0
testing/json_sample
Normal file
Binary file not shown.
BIN
testing/mfile_test
Executable file
BIN
testing/mfile_test
Executable file
Binary file not shown.
7
testing/mfile_test.cpp
Normal file
7
testing/mfile_test.cpp
Normal 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
7
testing/testdata.data
Normal 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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user