Added ZString.c_str() function; Added MStrin operator=.
This commit is contained in:
1 parent
2a4fc0ad6f
commit
287933f9ce
7 files changed
+60
-5
No files matched your search
+15
-4
@@ -46,6 +46,11 @@ namespace coreutils {
|
||||
cursor = (char *)data.c_str();
|
||||
}
|
||||
|
||||
ZString::~ZString() {
|
||||
if(cdata)
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
bool ZString::operator<(const ZString &valuex) const {
|
||||
return (strncmp(cursor, valuex.cursor, (valuex.length <= length ? valuex.length : length)) < 0);
|
||||
}
|
||||
@@ -101,24 +106,30 @@ namespace coreutils {
|
||||
return std::string(data, len);
|
||||
}
|
||||
|
||||
char* ZString::c_str() {
|
||||
cdata = (char *)malloc(length + 1);
|
||||
strncpy(cdata, data, length);
|
||||
cdata[length] = '\0';
|
||||
return cdata;
|
||||
}
|
||||
|
||||
std::vector<ZString> &ZString::split(std::string delimiter, size_t maxSize)
|
||||
{
|
||||
coreutils::ZString zDelimiter((char *)delimiter.c_str(), delimiter.size());
|
||||
return split(zDelimiter, maxSize);
|
||||
}
|
||||
|
||||
std::vector<ZString> &ZString::split(ZString &delimiter, size_t maxSize)
|
||||
{
|
||||
std::vector<ZString> &ZString::split(ZString &delimiter, size_t maxSize) {
|
||||
list.clear();
|
||||
if (length == 0) {
|
||||
list.push_back(ZString(""));
|
||||
return list;
|
||||
}
|
||||
|
||||
maxSize = maxSize == 0 ? 255: maxSize;
|
||||
char *end = data + length;
|
||||
char *pos = cursor;
|
||||
while ((pos + delimiter.getLength()) <= end) {
|
||||
if ((strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) && (maxSize > 0))
|
||||
if ((strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) && (maxSize != 0))
|
||||
{
|
||||
list.push_back(ZString(cursor, pos - cursor));
|
||||
cursor = pos + delimiter.getLength();
|
||||
|
||||
Reference in new issue
Block a user