Completed cosing of substring.
This commit is contained in:
parent
39fd88cad9
commit
a1cc142a59
@ -171,6 +171,13 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::substring(int start, int len) {
|
ZString ZString::substring(int start, int len) {
|
||||||
|
char *end = data + length;
|
||||||
|
char *startChar = data + start;
|
||||||
|
char *endChar = startChar + len;
|
||||||
|
char newlen = endChar > end ? endChar - end: len;
|
||||||
|
if(startChar < end) {
|
||||||
|
return ZString(startChar, newlen);
|
||||||
|
}
|
||||||
return ZString();
|
return ZString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,5 +86,10 @@ int main(int argc, char **argv) {
|
|||||||
coreutils::ZString test15("xyx");
|
coreutils::ZString test15("xyx");
|
||||||
std::cout << test14.startsWithDouble() << ":" << test15.startsWithDouble() << std::endl;
|
std::cout << test14.startsWithDouble() << ":" << test15.startsWithDouble() << std::endl;
|
||||||
|
|
||||||
|
coreutils::ZString test16("This is a test of substring");
|
||||||
|
std::cout << test16.substring(10) << std::endl;
|
||||||
|
std::cout << test16.substring(10, 4) << std::endl;
|
||||||
|
std::cout << test16.substring(0, 7) << std::endl;
|
||||||
|
std::cout << test16.substring(18, 20) << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user