Fixed MString and MFile.
This commit is contained in:
parent
11d6f00bfb
commit
829dc1a3c7
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,15 +6,19 @@ 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
2
MFile.h
2
MFile.h
@ -25,7 +25,7 @@ namespace coreutils {
|
||||
std::ifstream inFile;
|
||||
std::ofstream outFile;
|
||||
|
||||
void onChange() override;
|
||||
// void onChange() override;
|
||||
void update();
|
||||
|
||||
};
|
||||
|
||||
@ -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;
|
||||
// }
|
||||
|
||||
@ -170,6 +170,12 @@ namespace coreutils {
|
||||
///
|
||||
///
|
||||
|
||||
MString &operator<<(std::ifstream &pf);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
MString &operator<<(std::ostream &out);
|
||||
|
||||
///
|
||||
|
||||
13
ZString.cpp
13
ZString.cpp
@ -117,9 +117,16 @@ 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() {
|
||||
|
||||
@ -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
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