more serious work on JString.
This commit is contained in:
parent
c6e0486c14
commit
0d60cce8dc
59
JString.cpp
59
JString.cpp
@ -33,7 +33,7 @@ namespace coreutils {
|
||||
throw coreutils::Exception("Fix me to accept integer type.");
|
||||
}
|
||||
} else {
|
||||
std::cout << "[" << unparsed() << "] >" << value << "<" << std::endl;
|
||||
// std::cout << "[" << unparsed() << "] >" << value << "<" << std::endl;
|
||||
MString key;
|
||||
if(notfirst)
|
||||
key << ",";
|
||||
@ -48,7 +48,7 @@ namespace coreutils {
|
||||
}
|
||||
}
|
||||
|
||||
ZString JString::find(ZString &path) {
|
||||
ZString JString::find(ZString path) {
|
||||
reset();
|
||||
if(locate(path)) {
|
||||
if(ifNext("\""))
|
||||
@ -64,23 +64,9 @@ namespace coreutils {
|
||||
return ZString();
|
||||
}
|
||||
|
||||
bool JString::locate(ZString &path) {
|
||||
std::cout << "path locate: " << path << std::endl;
|
||||
path.split(".", 1);
|
||||
ZString pathx = path[0].getTokenExclude("[");
|
||||
ZString index;
|
||||
if(path[0].ifNext("[")) {
|
||||
index = path[0].getTokenExclude("]");
|
||||
if(path[0].ifNext("]")) {
|
||||
// TODO: index value here
|
||||
std::cout << ":::" << pathx << ":" << index << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
pathx = path[0];
|
||||
pathx.reset();
|
||||
index.reset();
|
||||
path[0].reset();
|
||||
bool JString::locate(ZString path) {
|
||||
// std::cout << "path locate: " << path << std::endl;
|
||||
path.getTokenExclude("[.");
|
||||
notfirst = false;
|
||||
if(ifNext("{")) {
|
||||
while(startsWith("\"")) {
|
||||
@ -93,13 +79,34 @@ namespace coreutils {
|
||||
} else
|
||||
throw coreutils::Exception("Labels must be contained in double quotes.");
|
||||
if(ifNext(":")) {
|
||||
// std::cout << "path: (" << pathx << ") " << label << std::endl;
|
||||
if(label == pathx) {
|
||||
if(path.getList().size() == 1) {
|
||||
std::cout << "found cursor: " << unparsed() << std::endl;
|
||||
// std::cout << "path: (" << path.parsed() << ") (" << label << ") " << (label == path.parsed()) << std::endl;
|
||||
if(label == path.parsed()) {
|
||||
if(path.unparsed() == "") {
|
||||
// std::cout << "found cursor: " << unparsed() << std::endl;
|
||||
return true;
|
||||
}
|
||||
return locate(path[1]);
|
||||
if(path.ifNext("."))
|
||||
return locate(path.unparsed());
|
||||
if(path.ifNext("[")) {
|
||||
int index = path.asInteger();
|
||||
if(!path.ifNext("]"))
|
||||
throw coreutils::Exception("expecting ] after index value in array selector.");
|
||||
if(ifNext("[")) {
|
||||
while(index > 0) {
|
||||
getContainer();
|
||||
if(!ifNext(","))
|
||||
throw coreutils::Exception("expecting comma to seperate array elements.");
|
||||
--index;
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
throw coreutils::Exception("Path is expecting an array for selector value.");
|
||||
if(path.eod())
|
||||
return false;
|
||||
else if(path.ifNext("."))
|
||||
return locate(path.unparsed());
|
||||
throw coreutils::Exception("expecting '.' in path.");
|
||||
}
|
||||
}
|
||||
// std::cout << "+++" << unparsed() << std::endl;
|
||||
if(startsWith("\"")) {
|
||||
@ -117,9 +124,9 @@ namespace coreutils {
|
||||
}
|
||||
} else if(ifNext("[")) {
|
||||
ZString label = path[0].getTokenExclude("[");
|
||||
path[0].ifNext("[");
|
||||
path.ifNext("[");
|
||||
ZString key = path[0].getTokenExclude("=");
|
||||
path[0].ifNext("=");
|
||||
path.ifNext("=");
|
||||
ZString value = path[0].getTokenExclude("]");
|
||||
while(!ifNext("]")) {
|
||||
push();
|
||||
|
@ -42,9 +42,9 @@ namespace coreutils {
|
||||
/// that begins the object's list.
|
||||
///
|
||||
|
||||
ZString find(ZString &path);
|
||||
ZString find(ZString path);
|
||||
|
||||
bool locate(ZString &path);
|
||||
bool locate(ZString path);
|
||||
bool notfirst;
|
||||
ZString path;
|
||||
|
||||
@ -82,7 +82,6 @@ namespace coreutils {
|
||||
}
|
||||
|
||||
JString & operator=(coreutils:: ZString value) {
|
||||
std::cout << "operator=" << value << std::endl;
|
||||
setSize(value.getLength());
|
||||
memcpy(data, value.getData(), value.getLength());
|
||||
length = value.getLength();
|
||||
|
17
MString.cpp
17
MString.cpp
@ -210,19 +210,19 @@ namespace coreutils {
|
||||
data[offset] = ch;
|
||||
}
|
||||
|
||||
void MString::insert(ZString &value, int offset) {
|
||||
void MString::insert(ZString value, int offset) {
|
||||
setSize(length + value.getLength());
|
||||
for (int ix = length; ix >= offset; ix--)
|
||||
getData()[ix + value.getLength()] = getData()[ix];
|
||||
getData()[ix] = getData()[ix - value.getLength()];
|
||||
std::memcpy(data + offset, value.getData(), value.getLength());
|
||||
}
|
||||
|
||||
void MString::insert(std::string value, int offset) {
|
||||
setSize(length + value.size());
|
||||
for (int ix = length; ix >= offset; ix--)
|
||||
getData()[ix + value.size()] = getData()[ix];
|
||||
std::memcpy(data + offset, value.c_str(), value.size());
|
||||
}
|
||||
// void MString::insert(std::string value, int offset) {
|
||||
// setSize(length + value.size());
|
||||
// for (int ix = length; ix >= offset; ix--)
|
||||
// getData()[ix + value.size()] = getData()[ix];
|
||||
// std::memcpy(data + offset, value.c_str(), value.size());
|
||||
// }
|
||||
|
||||
void MString::replace(char ch, int offset) {
|
||||
}
|
||||
@ -258,7 +258,6 @@ namespace coreutils {
|
||||
int newBufferSize = ((size / 256) + 1) * 256;
|
||||
if (bufferSize != newBufferSize) {
|
||||
bufferSize = newBufferSize;
|
||||
std::cout << "Adjusting storage size to " << bufferSize << " to accomodate " << size << "bytes." << std::endl;
|
||||
data = (char *)realloc(data, bufferSize);
|
||||
cursor = data + cursorOffset;
|
||||
}
|
||||
|
@ -176,13 +176,13 @@ namespace coreutils {
|
||||
///
|
||||
///
|
||||
|
||||
void insert(ZString &value, int offset);
|
||||
void insert(ZString value, int offset);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
void insert(std::string value, int offset);
|
||||
// void insert(std::string value, int offset);
|
||||
|
||||
///
|
||||
///
|
||||
|
@ -107,7 +107,7 @@ namespace coreutils {
|
||||
bool ZString::operator==(const ZString valuex) {
|
||||
if(valuex.getLength() != length)
|
||||
return false;
|
||||
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0);
|
||||
return (strncmp(data, valuex.data, length) == 0);
|
||||
}
|
||||
|
||||
bool ZString::operator!=(const ZString &valuex) const {
|
||||
@ -314,7 +314,7 @@ namespace coreutils {
|
||||
char previous = 0;
|
||||
char *start = cursor;
|
||||
do {
|
||||
while ((cursor <= (data + length)) && !isCharacter(*cursor, exclude)) {
|
||||
while ((cursor < (data + length)) && !isCharacter(*cursor, exclude)) {
|
||||
previous = *cursor;
|
||||
++cursor;
|
||||
}
|
||||
|
Binary file not shown.
@ -17,6 +17,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
test1["health"] = "100";
|
||||
test1["comment"] = "this is a comment";
|
||||
test1["racex"] = "elvin";
|
||||
test1["race"] = "human";
|
||||
test1["array"] = "[\"test1\",\"test2\",\"test3\"]";
|
||||
test1["tester"] = "test field";
|
||||
@ -32,6 +33,7 @@ int main(int argc, char **argv) {
|
||||
std::cout << test1["name"] << std::endl;
|
||||
std::cout << test1["health"] << std::endl;
|
||||
std::cout << test1["comment"] << std::endl;
|
||||
std::cout << test1["racex"] << std::endl;
|
||||
std::cout << test1["race"] << std::endl;
|
||||
std::cout << test1["array"] << std::endl;
|
||||
std::cout << test1["tester"] << std::endl;
|
||||
|
@ -8,11 +8,8 @@ int main(int argc, char **argv) {
|
||||
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
|
||||
test1 = "new value.";
|
||||
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
|
||||
std::cout << "001" << std::endl;
|
||||
std::string test11 = "this is a test";
|
||||
std::cout << "002" << std::endl;
|
||||
coreutils::MString test12 = test11;
|
||||
std::cout << "003" << std::endl;
|
||||
std::cout << "assign from std::string: [" << test12 << "]." << std::endl;
|
||||
|
||||
coreutils::MString test2("this is another test.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user