Index: src/OFMutableString.h ================================================================== --- src/OFMutableString.h +++ src/OFMutableString.h @@ -24,85 +24,85 @@ */ @interface OFMutableString: OFString /** * Sets the OFString to the specified UTF-8 encoded C string. * - * \param str A UTF-8 encoded C string to set the OFString to. + * \param string A UTF-8 encoded C string to set the OFString to. */ -- (void)setToCString: (const char*)str; +- (void)setToCString: (const char*)string; /** * Appends a UTF-8 encoded C string to the OFString. * - * \param str A UTF-8 encoded C string to append + * \param string A UTF-8 encoded C string to append */ -- (void)appendCString: (const char*)str; +- (void)appendCString: (const char*)string; /** * Appends a UTF-8 encoded C string with the specified length to the OFString. * - * \param str A UTF-8 encoded C string to append - * \param len The length of the UTF-8 encoded C string + * \param string A UTF-8 encoded C string to append + * \param length The length of the UTF-8 encoded C string */ -- (void)appendCString: (const char*)str - withLength: (size_t)len; +- (void)appendCString: (const char*)string + withLength: (size_t)length; /** * Appends a UTF-8 encoded C string to the OFString without checking whether it * is valid UTF-8. * * Only use this if you are 100% sure the string you append is either ASCII or * UTF-8! * - * \param str A UTF-8 encoded C string to append + * \param string A UTF-8 encoded C string to append */ -- (void)appendCStringWithoutUTF8Checking: (const char*)str; +- (void)appendCStringWithoutUTF8Checking: (const char*)string; /** * Appends a UTF-8 encoded C string with the specified length to the OFString * without checking whether it is valid UTF-8. * * Only use this if you are 100% sure the string you append is either ASCII or * UTF-8! * - * \param str A UTF-8 encoded C string to append - * \param len The length of the UTF-8 encoded C string - */ -- (void)appendCStringWithoutUTF8Checking: (const char*)str - length: (size_t)len; - -/** - * Appends another OFString to the OFString. - * - * \param str An OFString to append - */ -- (void)appendString: (OFString*)str; - -/** - * Appends a formatted UTF-8 encoded C string to the OFString. - * See printf for the format syntax. - * - * \param fmt A format string which generates the string to append - */ -- (void)appendFormat: (OFString*)fmt, ...; - -/** - * Appends a formatted UTF-8 encoded C string to the OFString. - * See printf for the format syntax. - * - * \param fmt A format string which generates the string to append - * \param args The arguments used in the format string - */ -- (void)appendFormat: (OFString*)fmt - withArguments: (va_list)args; - -/** - * Prepends another OFString to the OFString. - * - * \param str An OFString to prepend - */ -- (void)prependString: (OFString*)str; + * \param string A UTF-8 encoded C string to append + * \param length The length of the UTF-8 encoded C string + */ +- (void)appendCStringWithoutUTF8Checking: (const char*)string + length: (size_t)length; + +/** + * Appends another OFString to the OFString. + * + * \param string An OFString to append + */ +- (void)appendString: (OFString*)string; + +/** + * Appends a formatted UTF-8 encoded C string to the OFString. + * See printf for the format syntax. + * + * \param format A format string which generates the string to append + */ +- (void)appendFormat: (OFString*)format, ...; + +/** + * Appends a formatted UTF-8 encoded C string to the OFString. + * See printf for the format syntax. + * + * \param format A format string which generates the string to append + * \param arguments The arguments used in the format string + */ +- (void)appendFormat: (OFString*)format + withArguments: (va_list)arguments; + +/** + * Prepends another OFString to the OFString. + * + * \param string An OFString to prepend + */ +- (void)prependString: (OFString*)string; /** * Reverse the OFString. */ - (void)reverse; @@ -118,15 +118,15 @@ - (void)lower; /** * Inserts a string at the specified index. * - * \param str The string to insert - * \param idx The index + * \param string The string to insert + * \param index The index */ -- (void)insertString: (OFString*)str - atIndex: (size_t)idx; +- (void)insertString: (OFString*)string + atIndex: (size_t)index; /** * Deletes the characters at the specified range. * * \param start The index where the deletion should be started @@ -147,33 +147,33 @@ * Replaces the characters at the specified range. * * \param start The index where the replacement should be started * \param end The index until which the characters should be replaced. * This points BEHIND the last character! - * \param repl The string to the replace the characters with + * \param replacement The string to the replace the characters with */ - (void)replaceCharactersFromIndex: (size_t)start toIndex: (size_t)end - withString: (OFString*)repl; + withString: (OFString*)replacement; /** * Deletes the characters at the specified range. * * \param range The range of the characters which should be replaced - * \param repl The string to the replace the characters with + * \param replacement The string to the replace the characters with */ - (void)replaceCharactersInRange: (of_range_t)range - withString: (OFString*)repl; + withString: (OFString*)replacement; /** * Deletes all occurrences of a string with another string. * - * \param str The string to replace - * \param repl The string with which it should be replaced + * \param string The string to replace + * \param replacement The string with which it should be replaced */ -- (void)replaceOccurrencesOfString: (OFString*)str - withString: (OFString*)repl; +- (void)replaceOccurrencesOfString: (OFString*)string + withString: (OFString*)replacement; /** * Deletes all whitespaces at the beginning of a string. */ - (void)deleteLeadingWhitespaces; Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -41,20 +41,20 @@ #import "of_asprintf.h" #import "unicode.h" @implementation OFMutableString - (void)_applyTable: (const of_unichar_t* const[])table - withSize: (size_t)table_size + withSize: (size_t)tableSize { of_unichar_t c; - of_unichar_t *ustr; - size_t ulen, nlen, clen; + of_unichar_t *unicodeString; + size_t unicodeLen, newLength, cLen; size_t i, j, d; - char *nstr; + char *newString; if (!isUTF8) { - assert(table_size >= 1); + assert(tableSize >= 1); uint8_t *p = (uint8_t*)string + length; uint8_t t; while (--p >= (uint8_t*)string) @@ -62,85 +62,86 @@ *p = t; return; } - ulen = [self length]; - ustr = [self allocMemoryForNItems: ulen - withSize: sizeof(of_unichar_t)]; + unicodeLen = [self length]; + unicodeString = [self allocMemoryForNItems: unicodeLen + withSize: sizeof(of_unichar_t)]; i = j = 0; - nlen = 0; + newLength = 0; while (i < length) { - clen = of_string_utf8_to_unicode(string + i, length - i, &c); + cLen = of_string_utf8_to_unicode(string + i, length - i, &c); - if (clen == 0 || c > 0x10FFFF) { - [self freeMemory: ustr]; + if (cLen == 0 || c > 0x10FFFF) { + [self freeMemory: unicodeString]; @throw [OFInvalidEncodingException newWithClass: isa]; } - if (c >> 8 < table_size) { + if (c >> 8 < tableSize) { of_unichar_t tc = table[c >> 8][c & 0xFF]; if (tc) c = tc; } - ustr[j++] = c; + unicodeString[j++] = c; if (c < 0x80) - nlen++; + newLength++; else if (c < 0x800) - nlen += 2; + newLength += 2; else if (c < 0x10000) - nlen += 3; + newLength += 3; else if (c < 0x110000) - nlen += 4; + newLength += 4; else { - [self freeMemory: ustr]; + [self freeMemory: unicodeString]; @throw [OFInvalidEncodingException newWithClass: isa]; } - i += clen; + i += cLen; } @try { - nstr = [self allocMemoryWithSize: nlen + 1]; + newString = [self allocMemoryWithSize: newLength + 1]; } @catch (id e) { - [self freeMemory: ustr]; + [self freeMemory: unicodeString]; @throw e; } j = 0; - for (i = 0; i < ulen; i++) { - if ((d = of_string_unicode_to_utf8(ustr[i], nstr + j)) == 0) { - [self freeMemory: ustr]; - [self freeMemory: nstr]; + for (i = 0; i < unicodeLen; i++) { + if ((d = of_string_unicode_to_utf8(unicodeString[i], + newString + j)) == 0) { + [self freeMemory: unicodeString]; + [self freeMemory: newString]; @throw [OFInvalidEncodingException newWithClass: isa]; } j += d; } - assert(j == nlen); - nstr[j] = 0; - [self freeMemory: ustr]; + assert(j == newLength); + newString[j] = 0; + [self freeMemory: unicodeString]; [self freeMemory: string]; - string = nstr; - length = nlen; + string = newString; + length = newLength; } -- (void)setToCString: (const char*)str +- (void)setToCString: (const char*)string_ { size_t len; [self freeMemory: string]; - len = strlen(str); + len = strlen(string_); - switch (of_string_check_utf8(str, len)) { + switch (of_string_check_utf8(string_, len)) { case 0: isUTF8 = NO; break; case 1: isUTF8 = YES; @@ -153,102 +154,102 @@ @throw [OFInvalidEncodingException newWithClass: isa]; } length = len; string = [self allocMemoryWithSize: length + 1]; - memcpy(string, str, length + 1); + memcpy(string, string_, length + 1); } -- (void)appendCString: (const char*)str +- (void)appendCString: (const char*)string_ { - size_t strlength; + size_t len; - strlength = strlen(str); + len = strlen(string_); - switch (of_string_check_utf8(str, strlength)) { + switch (of_string_check_utf8(string_, len)) { case 1: isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException newWithClass: isa]; } string = [self resizeMemory: string - toSize: length + strlength + 1]; - memcpy(string + length, str, strlength + 1); - length += strlength; + toSize: length + len + 1]; + memcpy(string + length, string_, len + 1); + length += len; } -- (void)appendCString: (const char*)str - withLength: (size_t)len +- (void)appendCString: (const char*)string_ + withLength: (size_t)length_ { - switch (of_string_check_utf8(str, len)) { + switch (of_string_check_utf8(string_, length_)) { case 1: isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException newWithClass: isa]; } string = [self resizeMemory: string - toSize: length + len + 1]; - memcpy(string + length, str, len); - length += len; - string[length] = 0; -} - -- (void)appendCStringWithoutUTF8Checking: (const char*)str -{ - size_t strlength; - - strlength = strlen(str); - string = [self resizeMemory: string - toSize: length + strlength + 1]; - memcpy(string + length, str, strlength + 1); - length += strlength; -} - -- (void)appendCStringWithoutUTF8Checking: (const char*)str - length: (size_t)len -{ - string = [self resizeMemory: string - toSize: length + len + 1]; - memcpy(string + length, str, len); - length += len; - string[length] = 0; -} - -- (void)appendString: (OFString*)str -{ - if (str == nil) - @throw [OFInvalidArgumentException newWithClass: isa - selector: _cmd]; - - [self appendCString: [str cString]]; -} - -- (void)appendFormat: (OFString*)fmt, ... -{ - va_list args; - - va_start(args, fmt); - [self appendFormat: fmt - withArguments: args]; - va_end(args); -} - -- (void)appendFormat: (OFString*)fmt - withArguments: (va_list)args + toSize: length + length_ + 1]; + memcpy(string + length, string_, length_); + length += length_; + string[length] = 0; +} + +- (void)appendCStringWithoutUTF8Checking: (const char*)string_ +{ + size_t len; + + len = strlen(string_); + string = [self resizeMemory: string + toSize: length + len + 1]; + memcpy(string + length, string_, len + 1); + length += len; +} + +- (void)appendCStringWithoutUTF8Checking: (const char*)string_ + length: (size_t)length_ +{ + string = [self resizeMemory: string + toSize: length + length_ + 1]; + memcpy(string + length, string_, length_); + length += length_; + string[length] = 0; +} + +- (void)appendString: (OFString*)string_ +{ + if (string_ == nil) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + [self appendCString: [string_ cString]]; +} + +- (void)appendFormat: (OFString*)format, ... +{ + va_list arguments; + + va_start(arguments, format); + [self appendFormat: format + withArguments: arguments]; + va_end(arguments); +} + +- (void)appendFormat: (OFString*)format + withArguments: (va_list)arguments { char *t; int len; - if (fmt == nil) + if (format == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - if ((len = of_vasprintf(&t, [fmt cString], args)) == -1) + if ((len = of_vasprintf(&t, [format cString], arguments)) == -1) @throw [OFInvalidFormatException newWithClass: isa]; @try { [self appendCString: t withLength: len]; @@ -255,13 +256,13 @@ } @finally { free(t); } } -- (void)prependString: (OFString*)str +- (void)prependString: (OFString*)string_ { - return [self insertString: str + return [self insertString: string_ atIndex: 0]; } - (void)reverse { @@ -362,30 +363,31 @@ { [self _applyTable: of_unicode_lower_table withSize: OF_UNICODE_LOWER_TABLE_SIZE]; } -- (void)insertString: (OFString*)str - atIndex: (size_t)idx +- (void)insertString: (OFString*)string_ + atIndex: (size_t)index { - size_t nlen; + size_t newLength; if (isUTF8) - idx = of_string_index_to_position(string, idx, length); + index = of_string_index_to_position(string, index, length); - if (idx > length) + if (index > length) @throw [OFOutOfRangeException newWithClass: isa]; - nlen = length + [str cStringLength]; + newLength = length + [string_ cStringLength]; string = [self resizeMemory: string - toSize: nlen + 1]; + toSize: newLength + 1]; - memmove(string + idx + [str cStringLength], string + idx, length - idx); - memcpy(string + idx, [str cString], [str cStringLength]); - string[nlen] = '\0'; + memmove(string + index + [string_ cStringLength], string + index, + length - index); + memcpy(string + index, [string_ cString], [string_ cStringLength]); + string[newLength] = '\0'; - length = nlen; + length = newLength; } - (void)deleteCharactersFromIndex: (size_t)start toIndex: (size_t)end { @@ -420,13 +422,13 @@ toIndex: range.start + range.length]; } - (void)replaceCharactersFromIndex: (size_t)start toIndex: (size_t)end - withString: (OFString*)repl + withString: (OFString*)replacement { - size_t nlen; + size_t newLength; if (isUTF8) { start = of_string_index_to_position(string, start, length); end = of_string_index_to_position(string, end, length); } @@ -436,79 +438,81 @@ selector: _cmd]; if (end > length) @throw [OFOutOfRangeException newWithClass: isa]; - nlen = length - (end - start) + [repl cStringLength]; + newLength = length - (end - start) + [replacement cStringLength]; string = [self resizeMemory: string - toSize: nlen + 1]; + toSize: newLength + 1]; - memmove(string + end, string + start + [repl cStringLength], + memmove(string + end, string + start + [replacement cStringLength], length - end); - memcpy(string + start, [repl cString], [repl cStringLength]); - string[nlen] = '\0'; + memcpy(string + start, [replacement cString], + [replacement cStringLength]); + string[newLength] = '\0'; - length = nlen; + length = newLength; } - (void)replaceCharactersInRange: (of_range_t)range - withString: (OFString*)repl + withString: (OFString*)replacement { [self replaceCharactersFromIndex: range.start toIndex: range.start + range.length - withString: repl]; + withString: replacement]; } -- (void)replaceOccurrencesOfString: (OFString*)str - withString: (OFString*)repl -{ - const char *str_c = [str cString]; - const char *repl_c = [repl cString]; - size_t str_len = [str cStringLength]; - size_t repl_len = [repl cStringLength]; - size_t i, last, tmp_len; - char *tmp; - - if (str_len > length) +- (void)replaceOccurrencesOfString: (OFString*)string_ + withString: (OFString*)replacement +{ + const char *cString = [string_ cString]; + const char *replacementCString = [replacement cString]; + size_t stringLen = [string_ cStringLength]; + size_t replacementLen = [replacement cStringLength]; + size_t i, last, newLength; + char *newString; + + if (stringLen > length) return; - tmp = NULL; - tmp_len = 0; + newString = NULL; + newLength = 0; - for (i = 0, last = 0; i <= length - str_len; i++) { - if (memcmp(string + i, str_c, str_len)) + for (i = 0, last = 0; i <= length - stringLen; i++) { + if (memcmp(string + i, cString, stringLen)) continue; @try { - tmp = [self resizeMemory: tmp - toSize: tmp_len + i - last + - repl_len + 1]; + newString = [self resizeMemory: newString + toSize: newLength + i - last + + replacementLen + 1]; } @catch (id e) { - [self freeMemory: tmp]; + [self freeMemory: newString]; @throw e; } - memcpy(tmp + tmp_len, string + last, i - last); - memcpy(tmp + tmp_len + i - last, repl_c, repl_len); - tmp_len += i - last + repl_len; - i += str_len - 1; + memcpy(newString + newLength, string + last, i - last); + memcpy(newString + newLength + i - last, replacementCString, + replacementLen); + newLength += i - last + replacementLen; + i += stringLen - 1; last = i + 1; } @try { - tmp = [self resizeMemory: tmp - toSize: tmp_len + length - last + 1]; + newString = [self resizeMemory: newString + toSize: newLength + length - last + 1]; } @catch (id e) { - [self freeMemory: tmp]; + [self freeMemory: newString]; @throw e; } - memcpy(tmp + tmp_len, string + last, length - last); - tmp_len += length - last; - tmp[tmp_len] = 0; + memcpy(newString + newLength, string + last, length - last); + newLength += length - last; + newString[newLength] = 0; [self freeMemory: string]; - string = tmp; - length = tmp_len; + string = newString; + length = newLength; } - (void)deleteLeadingWhitespaces { size_t i; Index: src/OFString+Hashing.m ================================================================== --- src/OFString+Hashing.m +++ src/OFString+Hashing.m @@ -27,11 +27,11 @@ - (OFString*)MD5Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFMD5Hash MD5Hash]; uint8_t *digest; - char cString[OF_MD5_DIGEST_SIZE * 2]; + char ret[OF_MD5_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: string length: length]; digest = [hash digest]; @@ -40,26 +40,26 @@ uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; - cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); - cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); + ret[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); + ret[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } [pool release]; - return [OFString stringWithCString: cString + return [OFString stringWithCString: ret length: 32]; } - (OFString*)SHA1Hash { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMD5Hash *hash = [OFSHA1Hash SHA1Hash]; uint8_t *digest; - char cString[OF_SHA1_DIGEST_SIZE * 2]; + char ret[OF_SHA1_DIGEST_SIZE * 2]; size_t i; [hash updateWithBuffer: string length: length]; digest = [hash digest]; @@ -68,15 +68,15 @@ uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; - cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); - cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); + ret[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); + ret[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } [pool release]; - return [OFString stringWithCString: cString + return [OFString stringWithCString: ret length: 40]; } @end Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -63,73 +63,73 @@ + string; /** * Creates a new OFString from a UTF-8 encoded C string. * - * \param str A UTF-8 encoded C string to initialize the OFString with + * \param string A UTF-8 encoded C string to initialize the OFString with * \return A new autoreleased OFString */ -+ stringWithCString: (const char*)str; ++ stringWithCString: (const char*)string; /** * Creates a new OFString from a C string with the specified encoding. * - * \param str A C string to initialize the OFString with + * \param string A C string to initialize the OFString with * \param encoding The encoding of the C string * \return A new autoreleased OFString */ -+ stringWithCString: (const char*)str ++ stringWithCString: (const char*)string encoding: (of_string_encoding_t)encoding; /** * Creates a new OFString from a C string with the specified encoding and * length. * - * \param str A C string to initialize the OFString with + * \param string A C string to initialize the OFString with * \param encoding The encoding of the C string - * \param len The length of the C string + * \param length The length of the C string * \return A new autoreleased OFString */ -+ stringWithCString: (const char*)str ++ stringWithCString: (const char*)string encoding: (of_string_encoding_t)encoding - length: (size_t)len; + length: (size_t)length; /** * Creates a new OFString from a UTF-8 encoded C string with the specified * length. * - * \param str A UTF-8 encoded C string to initialize the OFString with - * \param len The length of the UTF-8 encoded C string + * \param string A UTF-8 encoded C string to initialize the OFString with + * \param length The length of the UTF-8 encoded C string * \return A new autoreleased OFString */ -+ stringWithCString: (const char*)str - length: (size_t)len; ++ stringWithCString: (const char*)string + length: (size_t)length; /** * Creates a new OFString from a format string. * See printf for the format syntax. * - * \param fmt A string used as format to initialize the OFString + * \param format A string used as format to initialize the OFString * \return A new autoreleased OFString */ -+ stringWithFormat: (OFString*)fmt, ...; ++ stringWithFormat: (OFString*)format, ...; /** * Creates a new OFString containing the constructed specified path. * - * \param first The first component of the path + * \param firstComponent The first component of the path * \return A new autoreleased OFString */ -+ stringWithPath: (OFString*)first, ...; ++ stringWithPath: (OFString*)firstComponent, ...; /** * Creates a new OFString from another string. * - * \param str A string to initialize the OFString with + * \param string A string to initialize the OFString with * \return A new autoreleased OFString */ -+ stringWithString: (OFString*)str; ++ stringWithString: (OFString*)string; /** * Creates a new OFString with the contents of the specified UTF-8 encoded file. * * \param path The path to the file @@ -150,116 +150,116 @@ /** * Creates a new OFString with the contents of the specified URL, assuming * UTF-8 encoding. * - * \param url The URL to the contents for the string + * \param URL The URL to the contents for the string * \return A new autoreleased OFString */ -+ stringWithContentsOfURL: (OFURL*)url; ++ stringWithContentsOfURL: (OFURL*)URL; /** * Creates a new OFString with the contents of the specified URL in the * specified encoding. * - * \param url The URL to the contents for the string + * \param URL The URL to the contents for the string * \param encoding The encoding to assume * \return A new autoreleased OFString */ -+ stringWithContentsOfURL: (OFURL*)url ++ stringWithContentsOfURL: (OFURL*)URL encoding: (of_string_encoding_t)encoding; /** * Initializes an already allocated OFString from a UTF-8 encoded C string. * - * \param str A UTF-8 encoded C string to initialize the OFString with + * \param string A UTF-8 encoded C string to initialize the OFString with * \return An initialized OFString */ -- initWithCString: (const char*)str; +- initWithCString: (const char*)string; /** * Initializes an already allocated OFString from a C string with the specified * encoding. * - * \param str A C string to initialize the OFString with + * \param string A C string to initialize the OFString with * \param encoding The encoding of the C string * \return An initialized OFString */ -- initWithCString: (const char*)str +- initWithCString: (const char*)string encoding: (of_string_encoding_t)encoding; /** * Initializes an already allocated OFString from a C string with the specified * encoding and length. * - * \param str A C string to initialize the OFString with - * \param encoding The encoding of the C string - * \param len The length of the C string - * \return An initialized OFString - */ -- initWithCString: (const char*)str - encoding: (of_string_encoding_t)encoding - length: (size_t)len; - -/** - * Initializes an already allocated OFString from a UTF-8 encoded C string with - * the specified length. - * - * \param str A UTF-8 encoded C string to initialize the OFString with - * \param len The length of the UTF-8 encoded C string - * \return An initialized OFString - */ -- initWithCString: (const char*)str - length: (size_t)len; - -/** - * Initializes an already allocated OFString with a format string. - * See printf for the format syntax. - * - * \param fmt A string used as format to initialize the OFString - * \return An initialized OFString - */ -- initWithFormat: (OFString*)fmt, ...; - -/** - * Initializes an already allocated OFString with a format string. - * See printf for the format syntax. - * - * \param fmt A string used as format to initialize the OFString - * \param args The arguments used in the format string - * \return An initialized OFString - */ -- initWithFormat: (OFString*)fmt - arguments: (va_list)args; - -/** - * Initializes an already allocated OFString with the constructed specified - * path. - * - * \param first The first component of the path - * \return A new autoreleased OFString - */ -- initWithPath: (OFString*)first, ...; - -/** - * Initializes an already allocated OFString with the constructed specified - * path. - * - * \param first The first component of the path - * \param args A va_list with the other components of the path - * \return A new autoreleased OFString - */ -- initWithPath: (OFString*)first - arguments: (va_list)args; - -/** - * Initializes an already allocated OFString with another string. - * - * \param str A string to initialize the OFString with - * \return An initialized OFString - */ -- initWithString: (OFString*)str; + * \param string A C string to initialize the OFString with + * \param encoding The encoding of the C string + * \param length The length of the C string + * \return An initialized OFString + */ +- initWithCString: (const char*)string + encoding: (of_string_encoding_t)encoding + length: (size_t)length; + +/** + * Initializes an already allocated OFString from a UTF-8 encoded C string with + * the specified length. + * + * \param string A UTF-8 encoded C string to initialize the OFString with + * \param length The length of the UTF-8 encoded C string + * \return An initialized OFString + */ +- initWithCString: (const char*)string + length: (size_t)length; + +/** + * Initializes an already allocated OFString with a format string. + * See printf for the format syntax. + * + * \param format A string used as format to initialize the OFString + * \return An initialized OFString + */ +- initWithFormat: (OFString*)format, ...; + +/** + * Initializes an already allocated OFString with a format string. + * See printf for the format syntax. + * + * \param format A string used as format to initialize the OFString + * \param arguments The arguments used in the format string + * \return An initialized OFString + */ +- initWithFormat: (OFString*)format + arguments: (va_list)arguments; + +/** + * Initializes an already allocated OFString with the constructed specified + * path. + * + * \param firstComponent The first component of the path + * \return A new autoreleased OFString + */ +- initWithPath: (OFString*)firstComponent, ...; + +/** + * Initializes an already allocated OFString with the constructed specified + * path. + * + * \param firstComponent The first component of the path + * \param arguments A va_list with the other components of the path + * \return A new autoreleased OFString + */ +- initWithPath: (OFString*)firstComponent + arguments: (va_list)arguments; + +/** + * Initializes an already allocated OFString with another string. + * + * \param string A string to initialize the OFString with + * \return An initialized OFString + */ +- initWithString: (OFString*)string; /** * Initializes an already allocated OFString with the contents of the specified * file in the specified encoding. * @@ -281,24 +281,24 @@ /** * Initializes an already allocated OFString with the contents of the specified * URL, assuming UTF-8 encoding. * - * \param url The URL to the contents for the string + * \param URL The URL to the contents for the string * \return An initialized OFString */ -- initWithContentsOfURL: (OFURL*)url; +- initWithContentsOfURL: (OFURL*)URL; /** * Initializes an already allocated OFString with the contents of the specified * URL in the specified encoding. * - * \param url The URL to the contents for the string + * \param URL The URL to the contents for the string * \param encoding The encoding to assume * \return An initialized OFString */ -- initWithContentsOfURL: (OFURL*)url +- initWithContentsOfURL: (OFURL*)URL encoding: (of_string_encoding_t)encoding; /** * \return The OFString as a UTF-8 encoded C string */ @@ -319,40 +319,40 @@ /// \endcond /** * Compares the OFString to another OFString without caring about the case. * - * \param str A string to compare with + * \param otherString A string to compare with * \return An of_comparison_result_t */ -- (of_comparison_result_t)caseInsensitiveCompare: (OFString*)str; +- (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString; /** * \param index The index of the Unicode character to return * \return The Unicode character at the specified index */ - (of_unichar_t)characterAtIndex: (size_t)index; /** - * \param str The string to search + * \param string The string to search * \return The index of the first occurrence of the string or OF_INVALID_INDEX * if it was not found */ -- (size_t)indexOfFirstOccurrenceOfString: (OFString*)str; +- (size_t)indexOfFirstOccurrenceOfString: (OFString*)string; /** - * \param str The string to search + * \param string The string to search * \return The index of the last occurrence of the string or OF_INVALID_INDEX if * it was not found */ -- (size_t)indexOfLastOccurrenceOfString: (OFString*)str; +- (size_t)indexOfLastOccurrenceOfString: (OFString*)string; /** - * \param str The string to search + * \param string The string to search * \return Whether the string contains the specified string */ -- (BOOL)containsString: (OFString*)str; +- (BOOL)containsString: (OFString*)string; /** * \param start The index where the substring starts * \param end The index where the substring ends. * This points BEHIND the last character! @@ -368,14 +368,14 @@ - (OFString*)substringWithRange: (of_range_t)range; /** * Creates a new string by appending another string. * - * \param str The string to append + * \param string The string to append * \return A new autoreleased OFString with the specified string appended */ -- (OFString*)stringByAppendingString: (OFString*)str; +- (OFString*)stringByAppendingString: (OFString*)string; /** * Creates a new string by deleting leading whitespaces. * * \return A new autoreleased OFString with leading whitespaces deleted Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -61,18 +61,18 @@ _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; }; static inline int -memcasecmp(const char *s1, const char *s2, size_t len) +memcasecmp(const char *first, const char *second, size_t len) { size_t i; for (i = 0; i < len; i++) { - if (tolower((int)s1[i]) > tolower((int)s2[i])) + if (tolower((int)first[i]) > tolower((int)second[i])) return OF_ORDERED_DESCENDING; - if (tolower((int)s1[i]) < tolower((int)s2[i])) + if (tolower((int)first[i]) < tolower((int)second[i])) return OF_ORDERED_ASCENDING; } return OF_ORDERED_SAME; } @@ -244,67 +244,67 @@ + string { return [[[self alloc] init] autorelease]; } -+ stringWithCString: (const char*)str -{ - return [[[self alloc] initWithCString: str] autorelease]; -} - -+ stringWithCString: (const char*)str - encoding: (of_string_encoding_t)encoding -{ - return [[[self alloc] initWithCString: str - encoding: encoding] autorelease]; -} - -+ stringWithCString: (const char*)str - encoding: (of_string_encoding_t)encoding - length: (size_t)len -{ - return [[[self alloc] initWithCString: str - encoding: encoding - length: len] autorelease]; -} - -+ stringWithCString: (const char*)str - length: (size_t)len -{ - return [[[self alloc] initWithCString: str - length: len] autorelease]; -} - -+ stringWithFormat: (OFString*)fmt, ... -{ - id ret; - va_list args; - - va_start(args, fmt); - ret = [[[self alloc] initWithFormat: fmt - arguments: args] autorelease]; - va_end(args); - - return ret; -} - -+ stringWithPath: (OFString*)first, ... -{ - id ret; - va_list args; - - va_start(args, first); - ret = [[[self alloc] initWithPath: first - arguments: args] autorelease]; - va_end(args); - - return ret; -} - -+ stringWithString: (OFString*)str -{ - return [[[self alloc] initWithString: str] autorelease]; ++ stringWithCString: (const char*)string +{ + return [[[self alloc] initWithCString: string] autorelease]; +} + ++ stringWithCString: (const char*)string + encoding: (of_string_encoding_t)encoding +{ + return [[[self alloc] initWithCString: string + encoding: encoding] autorelease]; +} + ++ stringWithCString: (const char*)string + encoding: (of_string_encoding_t)encoding + length: (size_t)length +{ + return [[[self alloc] initWithCString: string + encoding: encoding + length: length] autorelease]; +} + ++ stringWithCString: (const char*)string + length: (size_t)length +{ + return [[[self alloc] initWithCString: string + length: length] autorelease]; +} + ++ stringWithFormat: (OFString*)format, ... +{ + id ret; + va_list arguments; + + va_start(arguments, format); + ret = [[[self alloc] initWithFormat: format + arguments: arguments] autorelease]; + va_end(arguments); + + return ret; +} + ++ stringWithPath: (OFString*)firstComponent, ... +{ + id ret; + va_list arguments; + + va_start(arguments, firstComponent); + ret = [[[self alloc] initWithPath: firstComponent + arguments: arguments] autorelease]; + va_end(arguments); + + return ret; +} + ++ stringWithString: (OFString*)string +{ + return [[[self alloc] initWithString: string] autorelease]; } + stringWithContentsOfFile: (OFString*)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; @@ -315,19 +315,19 @@ { return [[[self alloc] initWithContentsOfFile: path encoding: encoding] autorelease]; } -+ stringWithContentsOfURL: (OFURL*)url ++ stringWithContentsOfURL: (OFURL*)URL { - return [[[self alloc] initWithContentsOfURL: url] autorelease]; + return [[[self alloc] initWithContentsOfURL: URL] autorelease]; } -+ stringWithContentsOfURL: (OFURL*)url ++ stringWithContentsOfURL: (OFURL*)URL encoding: (of_string_encoding_t)encoding { - return [[[self alloc] initWithContentsOfURL: url + return [[[self alloc] initWithContentsOfURL: URL encoding: encoding] autorelease]; } - init { @@ -342,73 +342,73 @@ } return self; } -- initWithCString: (const char*)str +- initWithCString: (const char*)string_ { - return [self initWithCString: str + return [self initWithCString: string_ encoding: OF_STRING_ENCODING_UTF_8 - length: strlen(str)]; + length: strlen(string_)]; } -- initWithCString: (const char*)str +- initWithCString: (const char*)string_ encoding: (of_string_encoding_t)encoding { - return [self initWithCString: str + return [self initWithCString: string_ encoding: encoding - length: strlen(str)]; + length: strlen(string_)]; } -- initWithCString: (const char*)str +- initWithCString: (const char*)string_ encoding: (of_string_encoding_t)encoding - length: (size_t)len + length: (size_t)length_ { self = [super init]; @try { size_t i, j; const uint16_t *table; if (encoding == OF_STRING_ENCODING_UTF_8 && - len >= 3 && !memcmp(str, "\xEF\xBB\xBF", 3)) { - str += 3; - len -= 3; + length_ >= 3 && !memcmp(string_, "\xEF\xBB\xBF", 3)) { + string_ += 3; + length_ -= 3; } - string = [self allocMemoryWithSize: len + 1]; - length = len; + string = [self allocMemoryWithSize: length_ + 1]; + length = length_; if (encoding == OF_STRING_ENCODING_UTF_8) { - switch (of_string_check_utf8(str, length)) { + switch (of_string_check_utf8(string_, length)) { case 1: isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException newWithClass: isa]; } - memcpy(string, str, length); + memcpy(string, string_, length); string[length] = 0; return self; } if (encoding == OF_STRING_ENCODING_ISO_8859_1) { - for (i = j = 0; i < len; i++) { + for (i = j = 0; i < length_; i++) { char buf[4]; size_t bytes; - if (!(str[i] & 0x80)) { - string[j++] = str[i]; + if (!(string_[i] & 0x80)) { + string[j++] = string_[i]; continue; } isUTF8 = YES; bytes = of_string_unicode_to_utf8( - (uint8_t)str[i], buf); + (uint8_t)string_[i], buf); if (bytes == 0) @throw [OFInvalidEncodingException newWithClass: isa]; @@ -434,39 +434,40 @@ break; default: @throw [OFInvalidEncodingException newWithClass: isa]; } - for (i = j = 0; i < len; i++) { + for (i = j = 0; i < length_; i++) { char buf[4]; - of_unichar_t chr; - size_t chr_bytes; + of_unichar_t character; + size_t characterBytes; - if (!(str[i] & 0x80)) { - string[j++] = str[i]; + if (!(string_[i] & 0x80)) { + string[j++] = string_[i]; continue; } - chr = table[(uint8_t)str[i]]; + character = table[(uint8_t)string_[i]]; - if (chr == 0xFFFD) + if (character == 0xFFFD) @throw [OFInvalidEncodingException newWithClass: isa]; isUTF8 = YES; - chr_bytes = of_string_unicode_to_utf8(chr, buf); + characterBytes = of_string_unicode_to_utf8(character, + buf); - if (chr_bytes == 0) + if (characterBytes == 0) @throw [OFInvalidEncodingException newWithClass: isa]; - length += chr_bytes - 1; + length += characterBytes - 1; string = [self resizeMemory: string toSize: length + 1]; - memcpy(string + j, buf, chr_bytes); - j += chr_bytes; + memcpy(string + j, buf, characterBytes); + j += characterBytes; } string[length] = 0; } @catch (id e) { [self release]; @@ -474,44 +475,45 @@ } return self; } -- initWithCString: (const char*)str - length: (size_t)len +- initWithCString: (const char*)string_ + length: (size_t)length_ { - return [self initWithCString: str + return [self initWithCString: string_ encoding: OF_STRING_ENCODING_UTF_8 - length: len]; + length: length_]; } -- initWithFormat: (OFString*)fmt, ... +- initWithFormat: (OFString*)format, ... { id ret; - va_list args; + va_list arguments; - va_start(args, fmt); - ret = [self initWithFormat: fmt - arguments: args]; - va_end(args); + va_start(arguments, format); + ret = [self initWithFormat: format + arguments: arguments]; + va_end(arguments); return ret; } -- initWithFormat: (OFString*)fmt - arguments: (va_list)args +- initWithFormat: (OFString*)format + arguments: (va_list)arguments { self = [super init]; @try { int len; - if (fmt == nil) + if (format == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - if ((len = of_vasprintf(&string, [fmt cString], args)) == -1) + if ((len = of_vasprintf(&string, [format cString], + arguments)) == -1) @throw [OFInvalidFormatException newWithClass: isa]; @try { length = len; @@ -534,46 +536,47 @@ } return self; } -- initWithPath: (OFString*)first, ... +- initWithPath: (OFString*)firstComponent, ... { id ret; - va_list args; + va_list arguments; - va_start(args, first); - ret = [self initWithPath: first - arguments: args]; - va_end(args); + va_start(arguments, firstComponent); + ret = [self initWithPath: firstComponent + arguments: arguments]; + va_end(arguments); return ret; } -- initWithPath: (OFString*)first - arguments: (va_list)args +- initWithPath: (OFString*)firstComponent + arguments: (va_list)arguments { self = [super init]; @try { OFString *component; size_t len, i; - va_list args2; + va_list argumentsCopy; - length = [first cStringLength]; + length = [firstComponent cStringLength]; - switch (of_string_check_utf8([first cString], length)) { + switch (of_string_check_utf8([firstComponent cString], + length)) { case 1: isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException newWithClass: isa]; } /* Calculate length */ - va_copy(args2, args); - while ((component = va_arg(args2, OFString*)) != nil) { + va_copy(argumentsCopy, arguments); + while ((component = va_arg(argumentsCopy, OFString*)) != nil) { len = [component cStringLength]; length += 1 + len; switch (of_string_check_utf8([component cString], len)) { @@ -586,15 +589,15 @@ } } string = [self allocMemoryWithSize: length + 1]; - len = [first cStringLength]; - memcpy(string, [first cString], len); + len = [firstComponent cStringLength]; + memcpy(string, [firstComponent cString], len); i = len; - while ((component = va_arg(args, OFString*)) != nil) { + while ((component = va_arg(arguments, OFString*)) != nil) { len = [component cStringLength]; string[i] = OF_PATH_DELIM; memcpy(string + i + 1, [component cString], len); i += len + 1; } @@ -606,18 +609,18 @@ } return self; } -- initWithString: (OFString*)str +- initWithString: (OFString*)string_ { self = [super init]; @try { /* We have no -[dealloc], so this is ok */ - string = (char*)[str cString]; - length = [str cStringLength]; + string = (char*)[string_ cString]; + length = [string_ cStringLength]; switch (of_string_check_utf8(string, length)) { case 1: isUTF8 = YES; break; @@ -688,49 +691,49 @@ [self freeMemory: tmp]; return self; } -- initWithContentsOfURL: (OFURL*)url +- initWithContentsOfURL: (OFURL*)URL { - return [self initWithContentsOfURL: url + return [self initWithContentsOfURL: URL encoding: OF_STRING_ENCODING_UTF_8]; } -- initWithContentsOfURL: (OFURL*)url +- initWithContentsOfURL: (OFURL*)URL encoding: (of_string_encoding_t)encoding { OFAutoreleasePool *pool; - OFHTTPRequest *req; - OFHTTPRequestResult *res; + OFHTTPRequest *request; + OFHTTPRequestResult *result; Class c; c = isa; [self release]; self = nil; pool = [[OFAutoreleasePool alloc] init]; - if ([[url scheme] isEqual: @"file"]) { - self = [[c alloc] initWithContentsOfFile: [url path] + if ([[URL scheme] isEqual: @"file"]) { + self = [[c alloc] initWithContentsOfFile: [URL path] encoding: encoding]; [pool release]; return self; } - req = [OFHTTPRequest requestWithURL: url]; - res = [req perform]; + request = [OFHTTPRequest requestWithURL: URL]; + result = [request perform]; - if ([res statusCode] != 200) + if ([result statusCode] != 200) @throw [OFHTTPRequestFailedException - newWithClass: [req class] - HTTPRequest: req - statusCode: [res statusCode]]; + newWithClass: [request class] + HTTPRequest: request + statusCode: [result statusCode]]; - self = [[c alloc] initWithCString: (char*)[[res data] cArray] + self = [[c alloc] initWithCString: (char*)[[result data] cArray] encoding: encoding - length: [[res data] count]]; + length: [[result data] count]]; [pool release]; return self; } - (const char*)cString @@ -753,15 +756,20 @@ - (BOOL)isUTF8 { return isUTF8; } -- (BOOL)isEqual: (id)obj +- (BOOL)isEqual: (id)object { - if (![obj isKindOfClass: [OFString class]]) + OFString *otherString; + + if (![object isKindOfClass: [OFString class]]) return NO; - if (strcmp(string, [(OFString*)obj cString])) + + otherString = (OFString*)object; + + if (strcmp(string, [otherString cString])) return NO; return YES; } @@ -773,26 +781,29 @@ - mutableCopy { return [[OFMutableString alloc] initWithString: self]; } -- (of_comparison_result_t)compare: (id)obj +- (of_comparison_result_t)compare: (id)object { - size_t str_len, min_len; + OFString *otherString; + size_t otherLen, minLen; int cmp; - if (![obj isKindOfClass: [OFString class]]) + if (![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - str_len = [(OFString*)obj cStringLength]; - min_len = (length > str_len ? str_len : length); + otherString = (OFString*)object; - if ((cmp = memcmp(string, [(OFString*)obj cString], min_len)) == 0) { - if (length > str_len) + otherLen = [otherString cStringLength]; + minLen = (length > otherLen ? otherLen : length); + + if ((cmp = memcmp(string, [otherString cString], minLen)) == 0) { + if (length > otherLen) return OF_ORDERED_DESCENDING; - if (length < str_len) + if (length < otherLen) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } if (cmp > 0) @@ -799,30 +810,30 @@ return OF_ORDERED_DESCENDING; else return OF_ORDERED_ASCENDING; } -- (of_comparison_result_t)caseInsensitiveCompare: (OFString*)str +- (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString; { - const char *str_cstr; - size_t i, j, str_len, min_len; + const char *otherCString; + size_t i, j, otherLen, minLen; int cmp; - if (![str isKindOfClass: [OFString class]]) + if (![otherString isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - str_cstr = [str cString]; - str_len = [str cStringLength]; + otherCString = [otherString cString]; + otherLen = [otherString cStringLength]; if (![self isUTF8]) { - min_len = (length > str_len ? str_len : length); + minLen = (length > otherLen ? otherLen : length); - if ((cmp = memcasecmp(string, [str cString], min_len)) == 0) { - if (length > str_len) + if ((cmp = memcasecmp(string, otherCString, minLen)) == 0) { + if (length > otherLen) return OF_ORDERED_DESCENDING; - if (length < str_len) + if (length < otherLen) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } if (cmp > 0) @@ -831,16 +842,17 @@ return OF_ORDERED_ASCENDING; } i = j = 0; - while (i < length && j < str_len) { + while (i < length && j < otherLen) { of_unichar_t c1, c2; size_t l1, l2; l1 = of_string_utf8_to_unicode(string + i, length - i, &c1); - l2 = of_string_utf8_to_unicode(str_cstr + j, str_len - j, &c2); + l2 = of_string_utf8_to_unicode(otherCString + j, otherLen - j, + &c2); if (l1 == 0 || l2 == 0 || c1 > 0x10FFFF || c2 > 0x10FFFF) @throw [OFInvalidEncodingException newWithClass: isa]; if (c1 >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) { @@ -866,13 +878,13 @@ i += l1; j += l2; } - if (length - i > str_len - j) + if (length - i > otherLen - j) return OF_ORDERED_DESCENDING; - else if (length - i < str_len - j) + else if (length - i < otherLen - j) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } @@ -914,65 +926,65 @@ @throw [OFInvalidEncodingException newWithClass: isa]; return c; } -- (size_t)indexOfFirstOccurrenceOfString: (OFString*)str +- (size_t)indexOfFirstOccurrenceOfString: (OFString*)string_ { - const char *str_c = [str cString]; - size_t str_len = [str cStringLength]; + const char *cString = [string_ cString]; + size_t stringLen = [string_ cStringLength]; size_t i; - if (str_len == 0) + if (stringLen == 0) return 0; - if (str_len > length) + if (stringLen > length) return OF_INVALID_INDEX; - for (i = 0; i <= length - str_len; i++) - if (!memcmp(string + i, str_c, str_len)) + for (i = 0; i <= length - stringLen; i++) + if (!memcmp(string + i, cString, stringLen)) return of_string_position_to_index(string, i); return OF_INVALID_INDEX; } -- (size_t)indexOfLastOccurrenceOfString: (OFString*)str +- (size_t)indexOfLastOccurrenceOfString: (OFString*)string_ { - const char *str_c = [str cString]; - size_t str_len = [str cStringLength]; + const char *cString = [string_ cString]; + size_t stringLen = [string_ cStringLength]; size_t i; - if (str_len == 0) + if (stringLen == 0) return of_string_position_to_index(string, length); - if (str_len > length) + if (stringLen > length) return OF_INVALID_INDEX; - for (i = length - str_len;; i--) { - if (!memcmp(string + i, str_c, str_len)) + for (i = length - stringLen;; i--) { + if (!memcmp(string + i, cString, stringLen)) return of_string_position_to_index(string, i); /* Did not match and we're at the last char */ if (i == 0) return OF_INVALID_INDEX; } } -- (BOOL)containsString: (OFString*)str +- (BOOL)containsString: (OFString*)string_ { - const char *str_c = [str cString]; - size_t str_len = [str cStringLength]; + const char *cString = [string_ cString]; + size_t stringLen = [string_ cStringLength]; size_t i; - if (str_len == 0) + if (stringLen == 0) return YES; - if (str_len > length) + if (stringLen > length) return NO; - for (i = 0; i <= length - str_len; i++) - if (!memcmp(string + i, str_c, str_len)) + for (i = 0; i <= length - stringLen; i++) + if (!memcmp(string + i, cString, stringLen)) return YES; return NO; } @@ -999,16 +1011,16 @@ { return [self substringFromIndex: range.start toIndex: range.start + range.length]; } -- (OFString*)stringByAppendingString: (OFString*)str +- (OFString*)stringByAppendingString: (OFString*)string_ { OFMutableString *new; new = [OFMutableString stringWithString: self]; - [new appendString: str]; + [new appendString: string_]; /* * Class swizzle the string to be immutable. We declared the return type * to be OFString*, so it can't be modified anyway. But not swizzling it * would create a real copy each time -[copy] is called. @@ -1088,30 +1100,30 @@ - (OFArray*)componentsSeparatedByString: (OFString*)delimiter { OFAutoreleasePool *pool; OFMutableArray *array; const char *delim = [delimiter cString]; - size_t delim_len = [delimiter cStringLength]; + size_t delimLen = [delimiter cStringLength]; size_t i, last; array = [OFMutableArray array]; pool = [[OFAutoreleasePool alloc] init]; - if (delim_len > length) { + if (delimLen > length) { [array addObject: [[self copy] autorelease]]; [pool release]; return array; } - for (i = 0, last = 0; i <= length - delim_len; i++) { - if (memcmp(string + i, delim, delim_len)) + for (i = 0, last = 0; i <= length - delimLen; i++) { + if (memcmp(string + i, delim, delimLen)) continue; [array addObject: [OFString stringWithCString: string + last length: i - last]]; - i += delim_len - 1; + i += delimLen - 1; last = i + 1; } [array addObject: [OFString stringWithCString: string + last]]; [pool release]; @@ -1127,27 +1139,27 @@ - (OFArray*)pathComponents { OFMutableArray *ret; OFAutoreleasePool *pool; - size_t i, last = 0, path_len = length; + size_t i, last = 0, pathLen = length; ret = [OFMutableArray array]; - if (path_len == 0) + if (pathLen == 0) return ret; pool = [[OFAutoreleasePool alloc] init]; #ifndef _WIN32 - if (string[path_len - 1] == OF_PATH_DELIM) + if (string[pathLen - 1] == OF_PATH_DELIM) #else - if (string[path_len - 1] == '/' || string[path_len - 1] == '\\') + if (string[pathLen - 1] == '/' || string[pathLen - 1] == '\\') #endif - path_len--; + pathLen--; - for (i = 0; i < path_len; i++) { + for (i = 0; i < pathLen; i++) { #ifndef _WIN32 if (string[i] == OF_PATH_DELIM) { #else if (string[i] == '/' || string[i] == '\\') { #endif @@ -1172,24 +1184,24 @@ return ret; } - (OFString*)lastPathComponent { - size_t path_len = length; + size_t pathLen = length; ssize_t i; - if (path_len == 0) + if (pathLen == 0) return @""; #ifndef _WIN32 - if (string[path_len - 1] == OF_PATH_DELIM) + if (string[pathLen - 1] == OF_PATH_DELIM) #else - if (string[path_len - 1] == '/' || string[path_len - 1] == '\\') + if (string[pathLen - 1] == '/' || string[pathLen - 1] == '\\') #endif - path_len--; + pathLen--; - for (i = path_len - 1; i >= 0; i--) { + for (i = pathLen - 1; i >= 0; i--) { #ifndef _WIN32 if (string[i] == OF_PATH_DELIM) { #else if (string[i] == '/' || string[i] == '\\') { #endif @@ -1204,32 +1216,32 @@ */ if (i < 0) i = 0; return [OFString stringWithCString: string + i - length: path_len - i]; + length: pathLen - i]; } - (OFString*)stringByDeletingLastPathComponent; { - size_t i, path_len = length; + size_t i, pathLen = length; - if (path_len == 0) + if (pathLen == 0) return @""; #ifndef _WIN32 - if (string[path_len - 1] == OF_PATH_DELIM) + if (string[pathLen - 1] == OF_PATH_DELIM) #else - if (string[path_len - 1] == '/' || string[path_len - 1] == '\\') + if (string[pathLen - 1] == '/' || string[pathLen - 1] == '\\') #endif - path_len--; + pathLen--; - if (path_len == 0) + if (pathLen == 0) return [OFString stringWithCString: string length: 1]; - for (i = path_len - 1; i >= 1; i--) + for (i = pathLen - 1; i >= 1; i--) #ifndef _WIN32 if (string[i] == OF_PATH_DELIM) #else if (string[i] == '/' || string[i] == '\\') #endif @@ -1353,24 +1365,24 @@ } - (float)floatValue { const char *str = string; - char *endptr; + char *endPtr; float value; /* Don't depend on isspace and thus the used locale */ while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r') str++; - value = strtof(str, &endptr); + value = strtof(str, &endPtr); /* Check if there are any invalid chars left */ - if (endptr != NULL) { - for (; *endptr != '\0'; endptr++) - if (*endptr != ' ' && *endptr != '\t' && - *endptr != '\n' && *endptr != '\r') + if (endPtr != NULL) { + for (; *endPtr != '\0'; endPtr++) + if (*endPtr != ' ' && *endPtr != '\t' && + *endPtr != '\n' && *endPtr != '\r') @throw [OFInvalidFormatException newWithClass: isa]; } return value; @@ -1377,24 +1389,24 @@ } - (double)doubleValue { const char *str = string; - char *endptr; + char *endPtr; double value; /* Don't depend on isspace and thus the used locale */ while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r') str++; - value = strtod(str, &endptr); + value = strtod(str, &endPtr); /* Check if there are any invalid chars left */ - if (endptr != NULL) { - for (; *endptr != '\0'; endptr++) - if (*endptr != ' ' && *endptr != '\t' && - *endptr != '\n' && *endptr != '\r') + if (endPtr != NULL) { + for (; *endPtr != '\0'; endPtr++) + if (*endPtr != ' ' && *endPtr != '\t' && + *endPtr != '\n' && *endPtr != '\r') @throw [OFInvalidFormatException newWithClass: isa]; } return value; @@ -1412,21 +1424,21 @@ i = j = 0; while (i < length) { of_unichar_t c; - size_t clen; + size_t cLen; - clen = of_string_utf8_to_unicode(string + i, length - 1, &c); + cLen = of_string_utf8_to_unicode(string + i, length - 1, &c); - if (clen == 0 || c > 0x10FFFF) { + if (cLen == 0 || c > 0x10FFFF) { free(ret); @throw [OFInvalidEncodingException newWithClass: isa]; } ret[j++] = c; - i += clen; + i += cLen; } ret[j] = 0; return ret; Index: src/base64.m ================================================================== --- src/base64.m +++ src/base64.m @@ -38,23 +38,23 @@ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 }; OFString* -of_base64_encode(const char *data, size_t length) +of_base64_encode(const char *data, size_t len) { OFMutableString *ret = [OFMutableString string]; - uint8_t *buffer = (uint8_t*)data; + uint8_t *buf = (uint8_t*)data; size_t i; uint8_t rest; char tb[4]; uint32_t sb; - rest = length % 3; + rest = len % 3; - for (i = 0; i < length - rest; i += 3) { - sb = (buffer[i] << 16) | (buffer[i + 1] << 8) | buffer[i + 2]; + for (i = 0; i < len - rest; i += 3) { + sb = (buf[i] << 16) | (buf[i + 1] << 8) | buf[i + 2]; tb[0] = of_base64_encode_table[(sb & 0xFC0000) >> 18]; tb[1] = of_base64_encode_table[(sb & 0x03F000) >> 12]; tb[2] = of_base64_encode_table[(sb & 0x000FC0) >> 6]; tb[3] = of_base64_encode_table[sb & 0x00003F]; @@ -63,20 +63,20 @@ length: 4]; } switch (rest) { case 1: - tb[0] = of_base64_encode_table[buffer[i] >> 2]; - tb[1] = of_base64_encode_table[(buffer[i] & 3) << 4]; + tb[0] = of_base64_encode_table[buf[i] >> 2]; + tb[1] = of_base64_encode_table[(buf[i] & 3) << 4]; tb[2] = tb[3] = '='; [ret appendCStringWithoutUTF8Checking: tb length: 4]; break; case 2: - sb = (buffer[i] << 16) | (buffer[i + 1] << 8); + sb = (buf[i] << 16) | (buf[i + 1] << 8); tb[0] = of_base64_encode_table[(sb & 0xFC0000) >> 18]; tb[1] = of_base64_encode_table[(sb & 0x03F000) >> 12]; tb[2] = of_base64_encode_table[(sb & 0x000FC0) >> 6]; tb[3] = '='; @@ -95,13 +95,13 @@ ret->isa = [OFString class]; return ret; } BOOL -of_base64_decode(OFDataArray *data, const char *cString, size_t len) +of_base64_decode(OFDataArray *data, const char *str, size_t len) { - const uint8_t *buffer = (const uint8_t*)cString; + const uint8_t *buf = (const uint8_t*)str; size_t i; if ((len & 3) != 0) return NO; @@ -109,39 +109,39 @@ uint32_t sb = 0; uint8_t count = 3; char db[3]; char tmp; - if (buffer[i] > 0x7F || buffer[i + 1] > 0x7F || - buffer[i + 2] > 0x7F || buffer[i + 3] > 0x7F) + if (buf[i] > 0x7F || buf[i + 1] > 0x7F || + buf[i + 2] > 0x7F || buf[i + 3] > 0x7F) return NO; - if (buffer[i] == '=' || buffer[i + 1] == '=' || - (buffer[i + 2] == '=' && buffer[i + 3] != '=')) + if (buf[i] == '=' || buf[i + 1] == '=' || + (buf[i + 2] == '=' && buf[i + 3] != '=')) return NO; - if (buffer[i + 2] == '=') + if (buf[i + 2] == '=') count--; - if (buffer[i + 3] == '=') + if (buf[i + 3] == '=') count--; - if ((tmp = of_base64_decode_table[buffer[i]]) == -1) + if ((tmp = of_base64_decode_table[buf[i]]) == -1) return NO; sb |= tmp << 18; - if ((tmp = of_base64_decode_table[buffer[i + 1]]) == -1) + if ((tmp = of_base64_decode_table[buf[i + 1]]) == -1) return NO; sb |= tmp << 12; - if ((tmp = of_base64_decode_table[buffer[i + 2]]) == -1) + if ((tmp = of_base64_decode_table[buf[i + 2]]) == -1) return NO; sb |= tmp << 6; - if ((tmp = of_base64_decode_table[buffer[i + 3]]) == -1) + if ((tmp = of_base64_decode_table[buf[i + 3]]) == -1) return NO; sb |= tmp; db[0] = (sb & 0xFF0000) >> 16;