Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -70,11 +70,11 @@ /** * \return The OFString as a C string, if possible (if not, returns NULL). * If not needed anymore, it is usefull to call freeMem:. */ -- (char*)cString; +- (char*)getCString; /** * \return The OFString as a wide C string */ - (wchar_t*)wideCString; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -86,11 +86,11 @@ } return self; } -- (char*)cString +- (char*)getCString { char *str; size_t len; if ((len = wcstombs(NULL, string, 0)) == (size_t)-1) { Index: tests/OFString/OFString.m ================================================================== --- tests/OFString/OFString.m +++ tests/OFString/OFString.m @@ -43,47 +43,48 @@ else { puts("s2 and s4 don't match!"); return 1; } - if (!strcmp([[s1 append: s2] cString], "test123")) + if (!strcmp([[s1 append: s2] getCString], "test123")) puts("s1 appended with s2 is the expected string! GOOD!"); else { puts("s1 appended with s2 is not the expected string!"); return 1; } - if (strlen([s1 cString]) == [s1 length] && [s1 length] == 7) + if (strlen([s1 getCString]) == [s1 length] && [s1 length] == 7) puts("s1 has the expected length. GOOD!"); else { puts("s1 does not have the expected length!"); return 1; } - if (!strcmp([[s1 reverse] cString], "321tset")) + if (!strcmp([[s1 reverse] getCString], "321tset")) puts("Reversed s1 is expected string! GOOD!"); else { puts("Reversed s1 is NOT the expected string!"); return 1; } - if (!strcmp([[s1 upper] cString], "321TSET")) + if (!strcmp([[s1 upper] getCString], "321TSET")) puts("Upper s1 is expected string! GOOD!"); else { puts("Upper s1 is NOT expected string!"); return 1; } - if (!strcmp([[s1 lower] cString], "321tset")) + if (!strcmp([[s1 lower] getCString], "321tset")) puts("Lower s1 is expected string! GOOD!"); else { puts("Lower s1 is NOT expected string!"); return 1; } + /* Also clears all the memory of the returned C strings */ [s1 free]; [s2 free]; [s3 free]; [s4 free]; return 0; }