Completed ZString::compare method.
This commit is contained in:
parent
6409bd2444
commit
ad74a9de85
19
ZString.cpp
19
ZString.cpp
@ -1,3 +1,4 @@
|
||||
|
||||
#include "ZString.h"
|
||||
#include "Log.h"
|
||||
#include "Exception.h"
|
||||
@ -251,7 +252,23 @@ namespace coreutils {
|
||||
}
|
||||
|
||||
int ZString::compare(ZString zstring) {
|
||||
|
||||
char *end1 = data + length;
|
||||
char *end2 = zstring.getData() + getLength();
|
||||
char *cursor1 = cursor;
|
||||
char *cursor2 = zstring.getCursor();
|
||||
while((cursor1 < end1) && (cursor2 < end2)) {
|
||||
if(*cursor1 < *cursor2)
|
||||
return -1;
|
||||
if(*cursor1 > *cursor2)
|
||||
return 1;
|
||||
++cursor1;
|
||||
++cursor2;
|
||||
}
|
||||
if((cursor1 == end1) && (cursor2 != end2))
|
||||
return -1;
|
||||
if((cursor2 == end2) && (cursor1 != end1))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ZString::equals(const char *value) {
|
||||
|
@ -69,6 +69,13 @@ int main(int argc, char **argv) {
|
||||
std::cout << test7.lineIsWhitespace() << test7.goeol() << std::endl;
|
||||
std::cout << test7.lineIsWhitespace() << test7.goeol() << std::endl;
|
||||
std::cout << test7.lineIsWhitespace() << test7.goeol() << std::endl;
|
||||
|
||||
|
||||
coreutils::ZString test8("value1");
|
||||
coreutils::ZString test9("value2");
|
||||
std::cout << test8.compare(test9) << ":" << test9.compare(test8) << ":" << test8.compare(test8) << std::endl;
|
||||
|
||||
coreutils::ZString test10("value1");
|
||||
coreutils::ZString test11("value1");
|
||||
std::cout << test10.compare(test11) << ":" << test11.compare(test10) << std::endl;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user