jstring changes
This commit is contained in:
parent
8f8c14d7b2
commit
f39bdc98f6
31
JString.h
31
JString.h
@ -18,11 +18,36 @@ namespace coreutils {
|
||||
|
||||
public:
|
||||
|
||||
MString & operator[](char *key);
|
||||
JString();
|
||||
JString(const char *data);
|
||||
|
||||
MString & operator[](ZString &key);
|
||||
void set(ZString path, const char *value);
|
||||
|
||||
MString & operator[](std::string key);
|
||||
///
|
||||
/// Use the find method to look through an object for member specified by
|
||||
/// the key in parameter 1. The cursor must be pointing to the { character
|
||||
/// that begins the object's list.
|
||||
///
|
||||
|
||||
ZString find(ZString path);
|
||||
|
||||
void operator=(ZString &value);
|
||||
JString& operator=(const char *value);
|
||||
|
||||
// ZString operator[](const char *path);
|
||||
JString& operator[](const char *path);
|
||||
// operator const ZString () const {
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
// MString & operator[](ZString &key);
|
||||
|
||||
// MString & operator[](std::string key);
|
||||
|
||||
private:
|
||||
bool locate(ZString path);
|
||||
bool notfirst;
|
||||
MString path;
|
||||
|
||||
};
|
||||
|
||||
|
@ -166,6 +166,7 @@ namespace coreutils {
|
||||
}
|
||||
|
||||
void MString::replace(ZString &value, int offset) {
|
||||
|
||||
}
|
||||
|
||||
void MString::replace(std::string value, int offset) {
|
||||
@ -202,4 +203,9 @@ namespace coreutils {
|
||||
length = size;
|
||||
}
|
||||
|
||||
int MString::offset() {
|
||||
return cursor - data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -134,6 +134,8 @@ namespace coreutils {
|
||||
|
||||
MString& write(ZString &value);
|
||||
|
||||
int offset();
|
||||
|
||||
private:
|
||||
int bufferSize = 0;
|
||||
void setSize(int size);
|
||||
|
40
ZString.cpp
40
ZString.cpp
@ -74,15 +74,15 @@ namespace coreutils {
|
||||
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0);
|
||||
}
|
||||
|
||||
bool ZString::operator==(std::string value) {
|
||||
if(value.length() != length)
|
||||
return false;
|
||||
return (strncmp(data, value.c_str(), length) == 0);
|
||||
}
|
||||
// bool ZString::operator==(std::string value) {
|
||||
// if(value.length() != length)
|
||||
// return false;
|
||||
// return (strncmp(data, value.c_str(), length) == 0);
|
||||
// }
|
||||
|
||||
bool ZString::operator==(const char *valuex) const {
|
||||
return (strncmp(data, valuex, length) == 0);
|
||||
}
|
||||
// bool ZString::operator==(const char *valuex) const {
|
||||
// return (strncmp(data, valuex, length) == 0);
|
||||
// }
|
||||
|
||||
bool ZString::operator!=(const ZString &valuex) const {
|
||||
// if(length != valuex.getLength())
|
||||
@ -210,6 +210,30 @@ namespace coreutils {
|
||||
return getTokenExclude(exclude.c_str());
|
||||
}
|
||||
|
||||
ZString ZString::getContainer() {
|
||||
char term = *cursor == '"' ? '"': *cursor == '(' ? ')': *cursor == '[' ? ']': *cursor == '{' ? '}': 0;
|
||||
if(!term)
|
||||
return ZString();
|
||||
char *start = cursor;
|
||||
char nest = *cursor;
|
||||
char *end = cursor + length;
|
||||
int level = 0;
|
||||
++cursor;
|
||||
while(cursor != end) {
|
||||
if(*cursor == term) {
|
||||
if(!level) {
|
||||
++cursor;
|
||||
return ZString(start, cursor - start);
|
||||
}
|
||||
--level;
|
||||
} else if(*cursor == nest) {
|
||||
++level;
|
||||
}
|
||||
++cursor;
|
||||
}
|
||||
return ZString();
|
||||
}
|
||||
|
||||
ZString &ZString::operator[](int index) {
|
||||
return list[index];
|
||||
}
|
||||
|
14
ZString.h
14
ZString.h
@ -105,8 +105,8 @@ namespace coreutils {
|
||||
|
||||
bool operator>(const ZString &valuex) const;
|
||||
bool operator==(const ZString &valuex);
|
||||
bool operator==(std::string value);
|
||||
bool operator==(const char *valuex) const;
|
||||
// bool operator==(std::string value);
|
||||
// bool operator==(const char *valuex) const;
|
||||
bool operator!=(const ZString &valuex) const;
|
||||
bool operator!=(const char *valuex) const;
|
||||
|
||||
@ -207,6 +207,14 @@ namespace coreutils {
|
||||
|
||||
ZString getTokenExclude(std::string exclude);
|
||||
|
||||
///
|
||||
/// If the cursor is over a container character then a call to this method
|
||||
/// will return the contents of the container. The cursor will remain at
|
||||
/// the position following the container.
|
||||
///
|
||||
|
||||
ZString getContainer();
|
||||
|
||||
///
|
||||
/// Use the [] operator to retrieve values delimited by the split method.
|
||||
///
|
||||
@ -358,9 +366,9 @@ namespace coreutils {
|
||||
char *cursor;
|
||||
size_t length;
|
||||
char *cdata = NULL;
|
||||
std::vector<ZString> list;
|
||||
|
||||
private:
|
||||
std::vector<ZString> list;
|
||||
std::stack<char *> stack;
|
||||
bool isCharacter(char ch, const char *string);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
g++ -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils
|
||||
g++ -o mstring_test mstring_test.cpp -I.. -L.. -lCoreUtils
|
||||
g++ -o jstring_test jstring_test.cpp -I.. -L.. -lCoreUtils
|
||||
|
Binary file not shown.
Binary file not shown.
@ -32,4 +32,11 @@ int main(int argc, char **argv) {
|
||||
coreutils::ZString test2("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
std::cout << "substring: [" << test2.substring(10) << "]" << std::endl;
|
||||
|
||||
// Test getContainer.
|
||||
|
||||
coreutils::ZString test4("test(this is a container (with a nesting))012345");
|
||||
test4.getTokenExclude("(");
|
||||
std::cout << "container: " << test4.getContainer() << std::endl;
|
||||
std::cout << "rest: " << test4.unparsed() << std::endl;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user