diff --git a/JString.cpp b/JString.cpp index 47923df..59267c1 100644 --- a/JString.cpp +++ b/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(); + } + } diff --git a/JString.h b/JString.h index 7b07b5b..357b5b4 100644 --- a/JString.h +++ b/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(); }; diff --git a/MString.cpp b/MString.cpp index 394de4a..6dbac9b 100644 --- a/MString.cpp +++ b/MString.cpp @@ -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); diff --git a/MString.h b/MString.h index 1d0c57f..6e75bb1 100644 --- a/MString.h +++ b/MString.h @@ -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); diff --git a/testing/jstring_test b/testing/jstring_test index edb5933..78eb5f6 100755 Binary files a/testing/jstring_test and b/testing/jstring_test differ diff --git a/testing/jstring_test.cpp b/testing/jstring_test.cpp index 0c90fe6..0a23e1e 100644 --- a/testing/jstring_test.cpp +++ b/testing/jstring_test.cpp @@ -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; }