Trying to fix MString assignments.

This commit is contained in:
Brad Arant 2023-10-10 15:49:46 -07:00
parent 74ab316e64
commit d020363bc9
12 changed files with 75 additions and 16 deletions

2
File.h
View File

@ -16,7 +16,7 @@ namespace coreutils {
class File {
public:
File(std::string fileName, int mode = O_RDONLY, int authority = 0664);
File(std::string fileName, int mode, int authority);
File(ZString &fileName, int mode = O_RDONLY, int authority = 0664);
~File();
void setBufferSize(size_t size);

33
JSONFile.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef __JSONFile_h__
#define __JSONFile_h__
#include "JString.h"
#include "File.h"
#include <iostream>
#include <sstream>
namespace coreutils {
///
/// Use the JSONFile object where you need a file based persistent backing store
/// for the JString style object.
///
class JSONFile : public JString : public File {
public:
JSONFile(ZString path): JString(), File(path, O_RDWR, 0644) {
}
virtual ~JSONFile() {
write(*this);
}
};
}
#endif

View File

@ -63,7 +63,7 @@ namespace coreutils {
if(label == path[0]) {
if(path.getList().size() == 1)
{
std::cout << "cursor: " << unparsed() << std::endl;
// std::cout << "cursor: " << unparsed() << std::endl;
return true;
}
return locate(path[1]);

View File

@ -56,9 +56,7 @@ namespace coreutils {
Proxy(JString &jstring, ZString key) : jstring(jstring), key(key) {}
operator coreutils::ZString () {
ZString result;
result = jstring.find(key);
return result;
return jstring.find(key);
}
Proxy& operator=(coreutils::ZString value) {

View File

@ -81,13 +81,20 @@ namespace coreutils {
return *this;
}
MString &MString::operator=(coreutils::ZString value) {
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
MString &MString::operator=(coreutils::ZString value) {
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(std::string value) {
setSize(value.length());
memcpy(data, value.c_str(), value.length());
length = value.length();
return *this;
}
MString &MString::operator=(const char *value) {
int len = strlen(value);
setSize(len);

View File

@ -94,9 +94,11 @@ namespace coreutils
///
/// Assignment operator will copy data to backing store.
///
MString &operator=(coreutils::MString data);
MString &operator=(coreutils::ZString data);
MString &operator=(coreutils::ZString value);
MString &operator=(std::string value);
///
/// Assignment operator will copy data to backing store.

1
testing/json.sample Normal file
View File

@ -0,0 +1 @@
{"name":"Stephonivich","race":"Human","health","100"}

Binary file not shown.

Binary file not shown.

View File

@ -19,7 +19,7 @@ int main(int argc, char **argv) {
coreutils::MString ytest("this is a test");
xtest = ytest;
std::cout << "assign mstring to mstring: " << xtest << std::endl;
// Character assignment tests.
coreutils::MString test3;
test3 = 'a';
@ -29,6 +29,7 @@ int main(int argc, char **argv) {
coreutils::MString test4;
test4 << "this is a test." << test7;
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
test4 << "another test " << 75;
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
@ -43,7 +44,7 @@ int main(int argc, char **argv) {
std::cout << "streaming from std::string: [" << test14 << "]." << std::endl;
coreutils::MString test9("XXXXXXXXXYYYYYYYYYY");
std::cout << "test insert: " << test9 << std::endl;
std::cout << "test insert: " << test9 << std::endl;
coreutils::MString test8("zzz");
test9.insert(test8, 9);
test9.insert("aaaaa", 9);
@ -64,10 +65,18 @@ int main(int argc, char **argv) {
coreutils::MString test21;
test21 = test20;
std::cout << "mstring = zstring: [" << test21 << "]" << std::endl;
coreutils::MString test22;
test22 << test20;
std::cout << "mstring << zstring: [" << test22 << "]" << std::endl;
std::string test23 = "this is a string";
test22 = test23;
std::cout << "mstring = string: [" << test22 << "]" << std::endl;
test22 << test23;
std::cout << "mstring << string: [" << test22 << "]" << std::endl;
return 0;
}

Binary file not shown.

View File

@ -1,5 +1,6 @@
#include <iostream>
#include "../ZString.h"
#include "../MString.h"
int main(int argc, char **argv) {
@ -44,4 +45,12 @@ int main(int argc, char **argv) {
std::cout << "find MX: " << testA.find("MX") << std::endl;
std::cout << "unparsed: " << testA.unparsed() << std::endl;
std::string testb = "this is a string";
coreutils::ZString testc = testb;
std::cout << testc << std::endl;
coreutils::MString testd = "this is an mstring";
testc = testd;
std::cout << testc << std::endl;
}