Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -9,10 +9,11 @@ * the packaging of this file. */ #import #import "OFObject.h" +#import "OFConstString.h" @interface OFString: OFObject { char *string; size_t length; @@ -21,10 +22,10 @@ + new: (const char*)str; - init; - init: (const char*)str; - (char*)cString; - (size_t)length; -- (OFString*)setTo: (const char*)str; +- (OFString*)setTo: (OFConstString*)str; - (OFString*)clone; -- (OFString*)append: (const char*)str; -- (int)compare: (OFString*)str; +- (OFString*)append: (OFConstString*)str; +- (int)compare: (OFConstString*)str; @end Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -48,27 +48,27 @@ - (size_t)length { return length; } -- (OFString*)setTo: (const char*)str +- (OFString*)setTo: (OFConstString*)str { char *newstr; size_t newlen; - if (str == NULL) { + if ([str cString] == NULL) { [self freeMem: string]; length = 0; string = NULL; return self; } - newlen = strlen(str); + newlen = [str length]; newstr = [self getMem: newlen + 1]; - memcpy(newstr, str, newlen + 1); + memcpy(newstr, [str cString], newlen + 1); if (string != NULL) [self freeMem: string]; length = newlen; @@ -80,32 +80,32 @@ - (OFString*)clone { return [OFString new: string]; } -- (OFString*)append: (const char*)str +- (OFString*)append: (OFConstString*)str { char *newstr; size_t newlen, strlength; if (str == NULL) - return [self setTo:str]; + return [self setTo: str]; - strlength = strlen(str); + strlength = [str length]; newlen = length + strlength; newstr = [self resizeMem: string toSize: newlen + 1]; - memcpy(newstr + length, str, strlength + 1); + memcpy(newstr + length, [str cString], strlength + 1); length = newlen; string = newstr; return self; } -- (int)compare: (OFString*)str +- (int)compare: (OFConstString*)str { return strcmp(string, [str cString]); } @end Index: src/OFWideString.h ================================================================== --- src/OFWideString.h +++ src/OFWideString.h @@ -9,11 +9,13 @@ * the packaging of this file. */ #import #import + #import "OFObject.h" +#import "OFConstWideString.h" @interface OFWideString: OFObject { wchar_t *wstring; size_t length; @@ -22,10 +24,10 @@ + new: (const wchar_t*)wstr; - init; - init: (const wchar_t*)wstr; - (wchar_t*)wcString; - (size_t)length; -- (OFWideString*)setTo: (const wchar_t*)wstr; +- (OFWideString*)setTo: (OFConstWideString*)wstr; - (OFWideString*)clone; -- (OFWideString*)append: (const wchar_t*)wstr; -- (int)compare: (OFWideString*)str; +- (OFWideString*)append: (OFConstWideString*)wstr; +- (int)compare: (OFConstWideString*)str; @end Index: src/OFWideString.m ================================================================== --- src/OFWideString.m +++ src/OFWideString.m @@ -33,11 +33,11 @@ length = 0; wstring = NULL; } else { length = wcslen(wstr); wstring = [self getMem: (length + 1) * sizeof(wchar_t)]; - memcpy(wstring, wstr, (length + 1) * sizeof(wchar_t)); + wmemcpy(wstring, wstr, length + 1); } } return self; } @@ -49,27 +49,27 @@ - (size_t)length { return length; } -- (OFWideString*)setTo: (const wchar_t*)wstr +- (OFWideString*)setTo: (OFConstWideString*)wstr { wchar_t *newstr; size_t newlen; - if (wstr == NULL) { + if ([wstr wcString] == NULL) { [self freeMem:wstring]; length = 0; wstring = NULL; return self; } - newlen = wcslen(wstr); + newlen = [wstr length]; newstr = [self getMem: (newlen + 1) * sizeof(wchar_t)]; - memcpy(newstr, wstr, (newlen + 1) * sizeof(wchar_t)); + wmemcpy(newstr, [wstr wcString], newlen + 1); if (wstring != NULL) [self freeMem: wstring]; length = newlen; @@ -81,32 +81,32 @@ - (OFWideString*)clone { return [OFWideString new: wstring]; } -- (OFWideString*)append: (const wchar_t*)wstr +- (OFWideString*)append: (OFConstWideString*)wstr { wchar_t *newstr; size_t newlen, strlength; - if (wstr == NULL) + if ([wstr wcString] == NULL) return [self setTo: wstr]; - strlength = wcslen(wstr); + strlength = [wstr length]; newlen = length + strlength; newstr = [self resizeMem: wstring toSize: (newlen + 1) * sizeof(wchar_t)]; - memcpy(newstr + length, wstr, (strlength + 1) * sizeof(wchar_t)); + wmemcpy(newstr + length, [wstr wcString], strlength + 1); length = newlen; wstring = newstr; return self; } -- (int)compare: (OFWideString*)str +- (int)compare: (OFConstWideString*)str { return wcscmp(wstring, [str wcString]); } @end Index: tests/OFString/OFString.m ================================================================== --- tests/OFString/OFString.m +++ tests/OFString/OFString.m @@ -22,30 +22,30 @@ OFString *s1 = [OFString new: "test"]; OFString *s2 = [[OFString alloc] init: ""]; OFString *s3; OFString *s4 = [OFString new]; - [s2 append: "123"]; + [s2 append: [OFConstString new: "123"]]; s3 = [s1 clone]; - [s4 setTo: [s2 cString]]; + [s4 setTo: (OFConstString*)s2]; - if (![s1 compare: s3]) + if (![s1 compare: (OFConstString*)s3]) puts("s1 and s3 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } - if (![s2 compare: s4]) + if (![s2 compare: (OFConstString*)s4]) puts("s2 and s4 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } - if (!strcmp([[s1 append: [s2 cString]] cString], "test123")) + if (!strcmp([[s1 append: (OFConstString*)s2] cString], "test123")) puts("s1 appended with s2 is the expected string! GOOD!"); else { puts("s1 appended with s2 is not the expected string!"); return 1; } Index: tests/OFWideString/OFWideString.m ================================================================== --- tests/OFWideString/OFWideString.m +++ tests/OFWideString/OFWideString.m @@ -21,30 +21,30 @@ OFWideString *s1 = [OFWideString new: L"test"]; OFWideString *s2 = [[OFWideString alloc] init: L""]; OFWideString *s3; OFWideString *s4 = [OFWideString new]; - [s2 append: L"123"]; + [s2 append: [OFConstWideString new: L"123"]]; s3 = [s1 clone]; - [s4 setTo: [s2 wcString]]; + [s4 setTo: (OFConstWideString*)s2]; - if (![s1 compare: s3]) + if (![s1 compare: (OFConstWideString*)s3]) puts("s1 and s3 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } - if (![s2 compare: s4]) + if (![s2 compare: (OFConstWideString*)s4]) puts("s2 and s4 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } - if (!wcscmp([[s1 append: [s2 wcString]] wcString], L"test123")) + if (!wcscmp([[s1 append: (OFConstWideString*)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; }