JString fix to compress initial assignment JSON.
This commit is contained in:
parent
83e9b8ca99
commit
95254310f0
23
JString.cpp
23
JString.cpp
@ -142,5 +142,26 @@ namespace coreutils {
|
||||
}
|
||||
// std::cout << "not found cursor: " << unparsed() << std::endl;
|
||||
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);
|
||||
}
|
||||
|
||||
JString & operator=(coreutils:: ZString value) {
|
||||
setSize(value.getLength());
|
||||
memcpy(data, value.getData(), value.getLength());
|
||||
length = value.getLength();
|
||||
return *this;
|
||||
}
|
||||
JString & operator=(coreutils:: ZString value);
|
||||
|
||||
private:
|
||||
void removeWhitespace();
|
||||
|
||||
};
|
||||
|
||||
|
@ -234,8 +234,14 @@ namespace coreutils {
|
||||
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) {
|
||||
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
|
||||
for (int ix = offset; ix < this->length; ix++)
|
||||
getData()[ix] = getData()[ix + length];
|
||||
setSize(this->length - length);
|
||||
|
@ -203,7 +203,13 @@ namespace coreutils {
|
||||
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);
|
||||
|
Binary file not shown.
@ -5,8 +5,9 @@
|
||||
|
||||
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 test9;
|
||||
|
||||
test1 = test0;
|
||||
std::cout << test1 << std::endl;
|
||||
@ -53,6 +54,10 @@ int main(int argc, char **argv) {
|
||||
coreutils::MString testout;
|
||||
testout << "this is a test: " << test1["comment"];
|
||||
std::cout << testout << std::endl;
|
||||
|
||||
test9 = test1["object1"];
|
||||
std::cout << test9 << std::endl;
|
||||
std::cout << test9["attr3"] << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user