Completed cosing of substring.

This commit is contained in:
Brad Arant 2024-08-08 11:42:09 -07:00
parent 39fd88cad9
commit a1cc142a59
2 changed files with 13 additions and 1 deletions

View File

@ -171,6 +171,13 @@ namespace coreutils {
}
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();
}

View File

@ -85,6 +85,11 @@ int main(int argc, char **argv) {
coreutils::ZString test14("25.5");
coreutils::ZString test15("xyx");
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;
}