JString fix to compress initial assignment JSON.
This commit is contained in:
parent
83e9b8ca99
commit
95254310f0
21
JString.cpp
21
JString.cpp
@ -143,4 +143,25 @@ namespace coreutils {
|
|||||||
// std::cout << "not found cursor: " << unparsed() << std::endl;
|
// std::cout << "not found cursor: " << unparsed() << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JString & JString::operator=(coreutils:: ZString value) {
|
||||||
|
setSize(value.getLength());
|
||||||
|
memcpy(data, value.getData(), value.getLength());
|
||||||
|
removeWhitespace();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JString::removeWhitespace() {
|
||||||
|
reset();
|
||||||
|
while(!eod()) {
|
||||||
|
if(*cursor == ' ')
|
||||||
|
remove(1);
|
||||||
|
else if(startsWith("\""))
|
||||||
|
getContainer();
|
||||||
|
else
|
||||||
|
++cursor;
|
||||||
|
}
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
JString.h
10
JString.h
@ -81,12 +81,10 @@ namespace coreutils {
|
|||||||
return Proxy(*this, key);
|
return Proxy(*this, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
JString & operator=(coreutils:: ZString value) {
|
JString & operator=(coreutils:: ZString value);
|
||||||
setSize(value.getLength());
|
|
||||||
memcpy(data, value.getData(), value.getLength());
|
private:
|
||||||
length = value.getLength();
|
void removeWhitespace();
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -234,8 +234,14 @@ namespace coreutils {
|
|||||||
void MString::replace(std::string value, int offset) {
|
void MString::replace(std::string value, int offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MString::remove(int length) {
|
||||||
|
int len = (data + this->length - cursor);
|
||||||
|
for (int ix = 0; ix < len; ix++)
|
||||||
|
cursor[ix] = cursor[ix + length];
|
||||||
|
setSize(this->length - length);
|
||||||
|
}
|
||||||
|
|
||||||
void MString::remove(int offset, int length) {
|
void MString::remove(int offset, int length) {
|
||||||
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
|
|
||||||
for (int ix = offset; ix < this->length; ix++)
|
for (int ix = offset; ix < this->length; ix++)
|
||||||
getData()[ix] = getData()[ix + length];
|
getData()[ix] = getData()[ix + length];
|
||||||
setSize(this->length - length);
|
setSize(this->length - length);
|
||||||
|
@ -203,7 +203,13 @@ namespace coreutils {
|
|||||||
void replace(std::string value, int offset);
|
void replace(std::string value, int offset);
|
||||||
|
|
||||||
///
|
///
|
||||||
|
/// Remove specified number of characters at cursor.
|
||||||
///
|
///
|
||||||
|
|
||||||
|
void remove(int length);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Remove specified nummber of characters from specified offset.
|
||||||
///
|
///
|
||||||
|
|
||||||
void remove(int offset, int length);
|
void remove(int offset, int length);
|
||||||
|
Binary file not shown.
@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
coreutils::MString test0("{\"Number\":\"0\",\"id\":\"XXXXX\"}");
|
coreutils::MString test0("{ \"Number\": \"0\", \"id\": \"XXXXX\" }");
|
||||||
coreutils::JString test1;
|
coreutils::JString test1;
|
||||||
|
coreutils::JString test9;
|
||||||
|
|
||||||
test1 = test0;
|
test1 = test0;
|
||||||
std::cout << test1 << std::endl;
|
std::cout << test1 << std::endl;
|
||||||
@ -54,6 +55,10 @@ int main(int argc, char **argv) {
|
|||||||
testout << "this is a test: " << test1["comment"];
|
testout << "this is a test: " << test1["comment"];
|
||||||
std::cout << testout << std::endl;
|
std::cout << testout << std::endl;
|
||||||
|
|
||||||
|
test9 = test1["object1"];
|
||||||
|
std::cout << test9 << std::endl;
|
||||||
|
std::cout << test9["attr3"] << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user