Index: src/OFCString.h ================================================================== --- src/OFCString.h +++ src/OFCString.h @@ -66,6 +66,11 @@ * Append a C string to the OFCString. * * \param str A C string to append */ - appendCString: (const char*)str; + +/** + * Reverse the OFCString. + */ +- reverse; @end Index: src/OFCString.m ================================================================== --- src/OFCString.m +++ src/OFCString.m @@ -74,9 +74,22 @@ memcpy(newstr + length, str, strlength + 1); length = newlen; string = newstr; + + return self; +} + +- reverse +{ + size_t i, j, len = length / 2; + + for (i = 0, j = length - 1; i < len; i++, j--) { + string[i] ^= string[j]; + string[j] ^= string[i]; + string[i] ^= string[j]; + } return self; } @end Index: src/OFConstWideCString.h ================================================================== --- src/OFConstWideCString.h +++ src/OFConstWideCString.h @@ -32,11 +32,11 @@ - initAsConstWideCString: (const wchar_t*)str; /** * \return The OFConstWideCString as a constant wide C string */ -- (const wchar_t*)wcString; +- (const wchar_t*)wCString; /** * \return The length of the OFConstWideCString */ - (size_t)length; Index: src/OFConstWideCString.m ================================================================== --- src/OFConstWideCString.m +++ src/OFConstWideCString.m @@ -27,11 +27,11 @@ } } return self; } -- (const wchar_t*)wcString +- (const wchar_t*)wCString { return string; } - (size_t)length @@ -44,8 +44,8 @@ return [OFString newAsConstWideCString: string]; } - (int)compareTo: (OFString*)str { - return wcscmp(string, [str wcString]); + return wcscmp(string, [str wCString]); } @end Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -50,11 +50,11 @@ - (char*)cString; /** * \return The OFString as a C-type wide string of the type it was created as */ -- (wchar_t*)wcString; +- (wchar_t*)wCString; /** * \return The length of the OFString */ - (size_t)length; @@ -99,6 +99,11 @@ * Append a wide C string to the OFString. * * \param str A wide C string to append */ - appendWideCString: (const wchar_t*)str; + +/** + * Reverse the OFString. + */ +- reverse; @end Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -46,11 +46,11 @@ - (char*)cString { OF_NOT_IMPLEMENTED(NULL) } -- (wchar_t*)wcString +- (wchar_t*)wCString { OF_NOT_IMPLEMENTED(NULL) } - (size_t)length @@ -84,9 +84,14 @@ { OF_NOT_IMPLEMENTED(nil) } - appendWideCString: (const wchar_t*)str +{ + OF_NOT_IMPLEMENTED(nil) +} + +- reverse { OF_NOT_IMPLEMENTED(nil) } @end Index: src/OFWideCString.h ================================================================== --- src/OFWideCString.h +++ src/OFWideCString.h @@ -32,11 +32,11 @@ - initAsWideCString: (wchar_t*)str; /** * \return The OFWideCString as a wide C string */ -- (wchar_t*)wcString; +- (wchar_t*)wCString; /** * \return The length of the OFWideCString */ - (size_t)length; @@ -67,6 +67,11 @@ * Append a wide C string to the OFWideCString. * * \param str A wide C string to append */ - appendWideCString: (const wchar_t*)str; + +/** + * Reverse the OFWideCString. + */ +- reverse; @end Index: src/OFWideCString.m ================================================================== --- src/OFWideCString.m +++ src/OFWideCString.m @@ -33,11 +33,11 @@ } } return self; } -- (wchar_t*)wcString +- (wchar_t*)wCString { return string; } - (size_t)length @@ -50,16 +50,16 @@ return [OFString newAsWideCString: string]; } - (int)compareTo: (OFString*)str { - return wcscmp(string, [str wcString]); + return wcscmp(string, [str wCString]); } - append: (OFString*)str { - return [self appendWideCString: [str wcString]]; + return [self appendWideCString: [str wCString]]; } - appendWideCString: (const wchar_t*)str { wchar_t *newstr; @@ -77,9 +77,22 @@ wmemcpy(newstr + length, str, strlength + 1); length = newlen; string = newstr; + + return self; +} + +- reverse +{ + size_t i, j, len = length / 2; + + for (i = 0, j = length - 1; i < len; i++, j--) { + string[i] ^= string[j]; + string[j] ^= string[i]; + string[i] ^= string[j]; + } return self; } @end Index: tests/OFString/OFString.m ================================================================== --- tests/OFString/OFString.m +++ tests/OFString/OFString.m @@ -54,10 +54,17 @@ puts("s1 has the expected length. GOOD!"); else { puts("s1 does not have the expected length!"); return 1; } + + if (!strcmp([[s1 reverse] cString], "321tset")) + puts("Reversed s1 is expected string! GOOD!"); + else { + puts("Reversed s1 is NOT the expected string!"); + return 1; + } [s1 free]; [s2 free]; [s3 free]; [s4 free]; Index: tests/OFWideString/OFWideString.m ================================================================== --- tests/OFWideString/OFWideString.m +++ tests/OFWideString/OFWideString.m @@ -40,23 +40,30 @@ else { puts("s1 and s3 don't match!"); return 1; } - if (!wcscmp([[s1 append: s2] wcString], L"test123")) + if (!wcscmp([[s1 append: s2] wCString], L"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 (wcslen([s1 wcString]) == [s1 length] && [s1 length] == 7) + if (wcslen([s1 wCString]) == [s1 length] && [s1 length] == 7) puts("s1 has the expected length. GOOD!"); else { puts("s1 does not have the expected length!"); return 1; } + + if (!wcscmp([[s1 reverse] wCString], L"321tset")) + puts("Reversed s1 is expected string! GOOD!"); + else { + puts("Reversed s1 is NOT the expected string!"); + return 1; + } [s1 free]; [s2 free]; [s3 free]; [s4 free];