Fixed delimiter depth on ZString::split.
This commit is contained in:
parent
6697a59c43
commit
2a4fc0ad6f
@ -118,17 +118,18 @@ namespace coreutils {
|
||||
char *end = data + length;
|
||||
char *pos = cursor;
|
||||
while ((pos + delimiter.getLength()) <= end) {
|
||||
if (strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0)
|
||||
if ((strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) && (maxSize > 0))
|
||||
{
|
||||
list.push_back(ZString(cursor, pos - cursor));
|
||||
cursor = pos + delimiter.getLength();
|
||||
pos = cursor;
|
||||
--maxSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
list.push_back(ZString(cursor, pos - cursor));
|
||||
cursor = pos;
|
||||
return list;
|
||||
|
Binary file not shown.
@ -2,54 +2,17 @@
|
||||
#include "../ZString.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
coreutils::ZString test("character1111:22222:33333");
|
||||
|
||||
coreutils::ZString test("11111:22222:33333:44444");
|
||||
std::cout << "test pre-split: [" << test << "]." << std::endl;
|
||||
|
||||
test.split(":");
|
||||
test.split(":", 1);
|
||||
|
||||
std::cout << "test post-split: [" << test << "]." << std::endl;
|
||||
std::cout << "test sections: [" << test.getList().size() << "]." << std::endl;
|
||||
std::cout << test.getLength() << std::endl;
|
||||
|
||||
std::cout << test[0] << std::endl;
|
||||
std::cout << test[1] << std::endl;
|
||||
std::cout << test[2] << std::endl;
|
||||
for(int ix = 0; ix < test.getList().size(); ++ix)
|
||||
std::cout << ix << ":" << test[ix] << std::endl;
|
||||
|
||||
coreutils::ZString test2("character1111:::::22222:::::33333");
|
||||
|
||||
test2.split(":::::");
|
||||
|
||||
std::cout << "test string: [" << test2 << "]" << std::endl;
|
||||
std::cout << "length: [" << test2.getLength() << "]" << std::endl;
|
||||
|
||||
std::cout << "[" << test2[0] << "]" << std::endl;
|
||||
std::cout << "[" << test2[1] << "]" << std::endl;
|
||||
std::cout << "[" << test2[2] << "]" << std::endl;
|
||||
std::cout << "[" << test2[3] << "]" << std::endl;
|
||||
|
||||
coreutils::ZString boundary("----WebKitFormBoundary5hx9ixjfxtJ8nXNm");
|
||||
|
||||
coreutils::ZString test3("------WebKitFormBoundary5hx9ixjfxtJ8nXNm\r\n"
|
||||
"Content-Disposition: form-data; name=\"username\"\r\n"
|
||||
"\r\n"
|
||||
"test\r\n"
|
||||
"------WebKitFormBoundary5hx9ixjfxtJ8nXNm\r\n"
|
||||
"Content-Disposition: form-data; name=\"password\"\r\n"
|
||||
"\r\n"
|
||||
"test\r\n"
|
||||
"------WebKitFormBoundary5hx9ixjfxtJ8nXNm\r\n"
|
||||
"Content-Disposition: form-data; name=\"verify\"\r\n"
|
||||
"\r\n"
|
||||
"test\r\n"
|
||||
"------WebKitFormBoundary5hx9ixjfxtJ8nXNm--\r\n");
|
||||
|
||||
test3.split(boundary);
|
||||
|
||||
std::cout << "[" << test3[0] << "]" << std::endl;
|
||||
std::cout << "[" << test3[1] << "]" << std::endl;
|
||||
std::cout << "[" << test3[2] << "]" << std::endl;
|
||||
std::cout << "[" << test3[3] << "]" << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user