@@ -20,14 +20,10 @@ #include #include #include -#ifdef _WIN32 -# include -#endif - #import "OFString.h" #import "OFString_UTF8.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFFile.h" @@ -1469,37 +1465,42 @@ return new; } - (BOOL)hasPrefix: (OFString*)prefix { - OFAutoreleasePool *pool; of_unichar_t *tmp; const of_unichar_t *prefixString; size_t prefixLength; int compare; if ((prefixLength = [prefix length]) > [self length]) return NO; - tmp = alloca(prefixLength * sizeof(of_unichar_t)); - [self getCharacters: tmp - inRange: of_range(0, prefixLength)]; - - pool = [[OFAutoreleasePool alloc] init]; - - prefixString = [prefix unicodeString]; - compare = memcmp(tmp, prefixString, - prefixLength * sizeof(of_unichar_t)); - - [pool release]; + tmp = [self allocMemoryForNItems: prefixLength + ofSize: sizeof(of_unichar_t)]; + @try { + OFAutoreleasePool *pool; + + [self getCharacters: tmp + inRange: of_range(0, prefixLength)]; + + pool = [[OFAutoreleasePool alloc] init]; + + prefixString = [prefix unicodeString]; + compare = memcmp(tmp, prefixString, + prefixLength * sizeof(of_unichar_t)); + + [pool release]; + } @finally { + [self freeMemory: tmp]; + } return !compare; } - (BOOL)hasSuffix: (OFString*)suffix { - OFAutoreleasePool *pool; of_unichar_t *tmp; const of_unichar_t *suffixString; size_t length, suffixLength; int compare; @@ -1506,21 +1507,29 @@ if ((suffixLength = [suffix length]) > [self length]) return NO; length = [self length]; - tmp = alloca(suffixLength * sizeof(of_unichar_t)); - [self getCharacters: tmp - inRange: of_range(length - suffixLength, suffixLength)]; - - pool = [[OFAutoreleasePool alloc] init]; - - suffixString = [suffix unicodeString]; - compare = memcmp(tmp, suffixString, - suffixLength * sizeof(of_unichar_t)); - - [pool release]; + tmp = [self allocMemoryForNItems: suffixLength + ofSize: sizeof(of_unichar_t)]; + @try { + OFAutoreleasePool *pool; + + [self getCharacters: tmp + inRange: of_range(length - suffixLength, + suffixLength)]; + + pool = [[OFAutoreleasePool alloc] init]; + + suffixString = [suffix unicodeString]; + compare = memcmp(tmp, suffixString, + suffixLength * sizeof(of_unichar_t)); + + [pool release]; + } @finally { + [self freeMemory: tmp]; + } return !compare; } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter