Comment: | OFString: Move path handling into a category
This is the first step to have different versions of those for different This also has the nice side-effect of not having one implementation in |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7a488c30627b4c489d91014ec08054cd |
User & Date: | js on 2018-03-11 00:37:56 |
Other Links: | manifest | tags |
2018-03-11
| ||
11:27 | OFFileManager: fileURLWithPath: to convert to URL check-in: 711592a1c3 user: js tags: trunk | |
00:37 | OFString: Move path handling into a category check-in: 7a488c3062 user: js tags: trunk | |
2018-03-10
| ||
20:26 | configure: Use egrep_cpp_yes instead of yes check-in: d918acb99d user: js tags: trunk | |
Modified configure.ac from [fe1120cd41] to [026ea97419].
︙ | ︙ | |||
281 282 283 284 285 286 287 | TESTS_LIBS="-F../src -F../src/runtime $TESTS_LIBS" ], [ TESTS_LIBS="-lobjfw \${RUNTIME_LIBS} $TESTS_LIBS" TESTS_LIBS="-L../src -L../src/runtime $TESTS_LIBS" ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) | | | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | TESTS_LIBS="-F../src -F../src/runtime $TESTS_LIBS" ], [ TESTS_LIBS="-lobjfw \${RUNTIME_LIBS} $TESTS_LIBS" TESTS_LIBS="-L../src -L../src/runtime $TESTS_LIBS" ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [ AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}') AC_SUBST(TESTPLUGIN, "plugin") AC_DEFINE(OF_HAVE_PLUGINS, 1, [Whether we have plugin support]) AS_IF([test x"$build_framework" = x"yes"], [ TESTPLUGIN_LIBS="-F../../src -F../../src/runtime" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS -framework ObjFW" |
︙ | ︙ |
Modified src/Makefile from [9229e6eeb1] to [d9f762d49e].
︙ | ︙ | |||
114 115 116 117 118 119 120 | ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} SRCS_FILES = OFFile.m \ OFFileManager.m \ OFINICategory.m \ OFINIFile.m \ | | > | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} SRCS_FILES = OFFile.m \ OFFileManager.m \ OFINICategory.m \ OFINIFile.m \ OFSettings.m \ OFString+PathAdditions.m SRCS_PLUGINS = OFPlugin.m SRCS_SOCKETS = OFHTTPServer.m \ OFStreamSocket.m \ OFTCPSocket.m \ OFUDPSocket.m \ resolver.m \ socket.m |
︙ | ︙ |
Modified src/OFStdIOStream.m from [0a2b2bbcab] to [66757147ba].
︙ | ︙ | |||
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | void *pool = objc_autoreleasePoolPush(); OFDate *date; OFString *dateString, *me, *msg; va_list arguments; date = [OFDate date]; dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; me = [[OFApplication programName] lastPathComponent]; va_start(arguments, format); msg = [[[OFString alloc] initWithFormat: format arguments: arguments] autorelease]; va_end(arguments); [of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, | > > > > | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | void *pool = objc_autoreleasePoolPush(); OFDate *date; OFString *dateString, *me, *msg; va_list arguments; date = [OFDate date]; dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; #ifdef OF_HAVE_FILES me = [[OFApplication programName] lastPathComponent]; #else me = [OFApplication programName]; #endif va_start(arguments, format); msg = [[[OFString alloc] initWithFormat: format arguments: arguments] autorelease]; va_end(arguments); [of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, |
︙ | ︙ |
Added src/OFString+PathAdditions.h version [9ffc17fae1].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_PathAdditions_reference; #ifdef __cplusplus } #endif @interface OFString (PathAdditions) /*! * @brief The components of the string when interpreted as a path. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents; /*! * @brief The last path component of the string when interpreted as a path. */ @property (readonly, nonatomic) OFString *lastPathComponent; /*! * @brief The file extension of string when interpreted as a path. */ @property (readonly, nonatomic) OFString *pathExtension; /*! * @brief The directory name of the string when interpreted as a path. */ @property (readonly, nonatomic) OFString *stringByDeletingLastPathComponent; /*! * @brief The string with the file extension of the path removed. */ @property (readonly, nonatomic) OFString *stringByDeletingPathExtension; /*! * @brief The string interpreted as a path with relative sub paths resolved. */ @property (readonly, nonatomic) OFString *stringByStandardizingPath; /*! * @brief Creates a path from the specified path components. * * @param components An array of components for the path * @return A new autoreleased OFString */ + (OFString *)pathWithComponents: (OFArray OF_GENERIC(OFString *) *)components; /*! * @brief Creates a new string by appending a path component. * * @param component The path component to append * @return A new, autoreleased OFString with the path component appended */ - (OFString *)stringByAppendingPathComponent: (OFString *)component; @end OF_ASSUME_NONNULL_END |
Added src/OFString+PathAdditions.m version [fde00f0835].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components { OFMutableString *ret = [OFMutableString string]; bool first = true; for (OFString *component in components) { if (!first) [ret appendString: OF_PATH_DELIMITER_STRING]; [ret appendString: component]; first = false; } return ret; } - (OFArray *)pathComponents { OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); const char *cString = [self UTF8String]; size_t i, last = 0, pathCStringLength = [self UTF8StringLength]; if (pathCStringLength == 0) { objc_autoreleasePoolPop(pool); return ret; } if (OF_IS_PATH_DELIMITER(cString[pathCStringLength - 1])) pathCStringLength--; for (i = 0; i < pathCStringLength; i++) { if (OF_IS_PATH_DELIMITER(cString[i])) { [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; last = i + 1; } } [ret addObject: [OFString stringWithUTF8String: cString + last length: i - last]]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (OFString *)lastPathComponent { void *pool = objc_autoreleasePoolPush(); const char *cString = [self UTF8String]; size_t pathCStringLength = [self UTF8StringLength]; ssize_t i; OFString *ret; if (pathCStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (OF_IS_PATH_DELIMITER(cString[pathCStringLength - 1])) pathCStringLength--; if (pathCStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (pathCStringLength - 1 > SSIZE_MAX) @throw [OFOutOfRangeException exception]; for (i = pathCStringLength - 1; i >= 0; i--) { if (OF_IS_PATH_DELIMITER(cString[i])) { i++; break; } } /* * Only one component, but the trailing delimiter might have been * removed, so return a new string anyway. */ if (i < 0) i = 0; ret = [[OFString alloc] initWithUTF8String: cString + i length: pathCStringLength - i]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)pathExtension { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = [self lastPathComponent]; pos = [fileName rangeOfString: @"." options: OF_STRING_SEARCH_BACKWARDS].location; if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringWithRange: of_range(pos + 1, [fileName length] - pos - 1)]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByDeletingLastPathComponent { void *pool = objc_autoreleasePoolPush(); const char *cString = [self UTF8String]; size_t pathCStringLength = [self UTF8StringLength]; OFString *ret; if (pathCStringLength == 0) { objc_autoreleasePoolPop(pool); return @""; } if (OF_IS_PATH_DELIMITER(cString[pathCStringLength - 1])) pathCStringLength--; if (pathCStringLength == 0) { ret = [[OFString alloc] initWithUTF8String: cString length: 1]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } for (size_t i = pathCStringLength - 1; i >= 1; i--) { if (OF_IS_PATH_DELIMITER(cString[i])) { ret = [[OFString alloc] initWithUTF8String: cString length: i]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } } if (OF_IS_PATH_DELIMITER(cString[0])) { ret = [[OFString alloc] initWithUTF8String: cString length: 1]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } objc_autoreleasePoolPop(pool); return OF_PATH_CURRENT_DIRECTORY; } - (OFString *)stringByDeletingPathExtension { void *pool; OFMutableArray OF_GENERIC(OFString *) *components; OFString *ret, *fileName; size_t pos; if ([self length] == 0) return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[[self pathComponents] mutableCopy] autorelease]; fileName = [components lastObject]; pos = [fileName rangeOfString: @"." options: OF_STRING_SEARCH_BACKWARDS].location; if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringWithRange: of_range(0, pos)]; [components replaceObjectAtIndex: [components count] - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByStandardizingPath { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components = [self pathComponents]; OFMutableArray OF_GENERIC(OFString *) *array; OFString *ret; bool done = false, startsWithEmpty, endsWithEmpty; array = [[components mutableCopy] autorelease]; if ((startsWithEmpty = [[array firstObject] isEqual: @""])) [array removeObjectAtIndex: 0]; endsWithEmpty = [[array lastObject] isEqual: @""]; while (!done) { size_t length = [array count]; done = true; for (size_t i = 0; i < length; i++) { OFString *component = [array objectAtIndex: i]; OFString *parent = (i > 0 ? [array objectAtIndex: i - 1] : 0); if ([component isEqual: OF_PATH_CURRENT_DIRECTORY] || [component length] == 0) { [array removeObjectAtIndex: i]; done = false; break; } if ([component isEqual: OF_PATH_PARENT_DIRECTORY] && parent != nil && ![parent isEqual: OF_PATH_PARENT_DIRECTORY]) { [array removeObjectsInRange: of_range(i - 1, 2)]; done = false; break; } } } if (startsWithEmpty) [array insertObject: @"" atIndex: 0]; if (endsWithEmpty) [array addObject: @""]; ret = [[array componentsJoinedByString: OF_PATH_DELIMITER_STRING] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)stringByAppendingPathComponent: (OFString *)component { if ([self hasSuffix: OF_PATH_DELIMITER_STRING]) return [self stringByAppendingString: component]; else { OFMutableString *ret = [[self mutableCopy] autorelease]; [ret appendString: OF_PATH_DELIMITER_STRING]; [ret appendString: component]; [ret makeImmutable]; return ret; } } @end |
Modified src/OFString.h from [70879a2fc2] to [47bba28c27].
︙ | ︙ | |||
134 135 136 137 138 139 140 | @property (readonly, nonatomic) const char *UTF8String OF_RETURNS_INNER_POINTER; /*! * @brief The number of bytes the string needs in UTF-8 encoding. */ @property (readonly, nonatomic) size_t UTF8StringLength; | < < < < < < < < < < < < < < < | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | @property (readonly, nonatomic) const char *UTF8String OF_RETURNS_INNER_POINTER; /*! * @brief The number of bytes the string needs in UTF-8 encoding. */ @property (readonly, nonatomic) size_t UTF8StringLength; /*! * @brief The string in uppercase. */ @property (readonly, nonatomic) OFString *uppercaseString; /*! * @brief The string in lowercase. |
︙ | ︙ | |||
223 224 225 226 227 228 229 | * @brief The double value of the string as a double. * * If the string contains any non-number characters, an * OFInvalidEncodingException is thrown. */ @property (readonly, nonatomic) double doubleValue; | < < < < < < < < < < < < < < < | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | * @brief The double value of the string as a double. * * If the string contains any non-number characters, an * OFInvalidEncodingException is thrown. */ @property (readonly, nonatomic) double doubleValue; /*! * @brief The string interpreted as a URL path with relative sub paths resolved. * * This works similar to @ref stringByStandardizingPath, but is intended for * standardization of paths that are part of a URL. */ @property (readonly, nonatomic) OFString *stringByStandardizingURLPath; |
︙ | ︙ | |||
572 573 574 575 576 577 578 | * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding; #endif | < < < < < < < < | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding; #endif /*! * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return An initialized OFString */ |
︙ | ︙ | |||
1072 1073 1074 1075 1076 1077 1078 | * @param format A format string which generates the string to append * @param arguments The arguments used in the format string * @return A new, autoreleased OFString with the specified format appended */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments; | < < < < < < < < | 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 | * @param format A format string which generates the string to append * @param arguments The arguments used in the format string * @return A new, autoreleased OFString with the specified format appended */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments; /*! * @brief Creates a new string by appending a URL path component. * * @param component The URL path component to append * @return A new, autoreleased OFString with the URL path component appended */ - (OFString *)stringByAppendingURLPathComponent: (OFString *)component; |
︙ | ︙ | |||
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 | OF_ASSUME_NONNULL_END #import "OFConstantString.h" #import "OFMutableString.h" #import "OFString+CryptoHashing.h" #import "OFString+JSONValue.h" #import "OFString+Serialization.h" #import "OFString+URLEncoding.h" #import "OFString+XMLEscaping.h" #import "OFString+XMLUnescaping.h" #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* | > > > | 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 | OF_ASSUME_NONNULL_END #import "OFConstantString.h" #import "OFMutableString.h" #import "OFString+CryptoHashing.h" #import "OFString+JSONValue.h" #ifdef OF_HAVE_FILES # import "OFString+PathAdditions.h" #endif #import "OFString+Serialization.h" #import "OFString+URLEncoding.h" #import "OFString+XMLEscaping.h" #import "OFString+XMLUnescaping.h" #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* |
︙ | ︙ |
Modified src/OFString.m from [b00db1bc09] to [1c64791f79].
︙ | ︙ | |||
116 117 118 119 120 121 122 123 124 125 126 127 128 129 | /* References for static linking */ void _references_to_categories_of_OFString(void) { _OFString_CryptoHashing_reference = 1; _OFString_JSONValue_reference = 1; _OFString_Serialization_reference = 1; _OFString_URLEncoding_reference = 1; _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; } void | > > > | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | /* References for static linking */ void _references_to_categories_of_OFString(void) { _OFString_CryptoHashing_reference = 1; _OFString_JSONValue_reference = 1; #ifdef OF_HAVE_FILES _OFString_PathAdditions_reference = 1; #endif _OFString_Serialization_reference = 1; _OFString_URLEncoding_reference = 1; _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; } void |
︙ | ︙ | |||
281 282 283 284 285 286 287 | while (*string++ != 0) length++; return length; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | while (*string++ != 0) length++; return length; } static OFString * decomposedString(OFString *self, const char *const *const *table, size_t size) { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; size_t length = [self length]; |
︙ | ︙ | |||
808 809 810 811 812 813 814 | encoding: (of_string_encoding_t)encoding { return [[[self alloc] initWithContentsOfURL: URL encoding: encoding] autorelease]; } #endif | < < < < < < < < < < < < < < < < < | 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | encoding: (of_string_encoding_t)encoding { return [[[self alloc] initWithContentsOfURL: URL encoding: encoding] autorelease]; } #endif - (instancetype)init { if ([self isMemberOfClass: [OFString class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; |
︙ | ︙ | |||
2066 2067 2068 2069 2070 2071 2072 | arguments: arguments]; [new makeImmutable]; return new; } | < < < < < < < < < < < < < < < < | 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 | arguments: arguments]; [new makeImmutable]; return new; } - (OFString *)stringByAppendingURLPathComponent: (OFString *)component { if ([self hasSuffix: @"/"]) return [self stringByAppendingString: component]; else { OFMutableString *ret = [[self mutableCopy] autorelease]; |
︙ | ︙ | |||
2324 2325 2326 2327 2328 2329 2330 | [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 | [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (OFString *)stringByStandardizingURLPath { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *components = [self componentsSeparatedByString: @"/"]; OFMutableArray OF_GENERIC(OFString *) *array; OFString *ret; bool done = false, startsWithEmpty, endsWithEmpty; array = [[components mutableCopy] autorelease]; if ((startsWithEmpty = [[array firstObject] isEqual: @""])) [array removeObjectAtIndex: 0]; endsWithEmpty = [[array lastObject] isEqual: @""]; while (!done) { size_t length = [array count]; done = true; for (size_t i = 0; i < length; i++) { id object = [array objectAtIndex: i]; id parent; if (i > 0) parent = [array objectAtIndex: i - 1]; else parent = nil; if ([object isEqual: @"."] || [object length] == 0) { [array removeObjectAtIndex: i]; done = false; break; } if ([object isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: of_range(i - 1, 2)]; done = false; break; } } } if (startsWithEmpty) [array insertObject: @"" atIndex: 0]; if (endsWithEmpty) [array addObject: @""]; ret = [[array componentsJoinedByString: @"/"] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (intmax_t)decimalValue { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; size_t i = 0, length = [self length]; |
︙ | ︙ |
Modified src/OFString_UTF8.m from [d6a602d281] to [ec2d5729ba].
︙ | ︙ | |||
1156 1157 1158 1159 1160 1161 1162 | [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 | [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (const of_unichar_t *)characters { OFObject *object = [[[OFObject alloc] init] autorelease]; of_unichar_t *ret; size_t i, j; ret = [object allocMemoryWithSize: sizeof(of_unichar_t) |
︙ | ︙ |
Modified tests/OFStringTests.m from [0e68977055] to [979ff3e546].
︙ | ︙ | |||
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | TEST(@"-[stringByAppendingString:]", [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"]) TEST(@"-[stringByPrependingString:]", [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"]) s[0] = [mutableStringClass stringWithString: @"foo"]; [s[0] appendString: OF_PATH_DELIMITER_STRING]; [s[0] appendString: @"bar"]; s[1] = [mutableStringClass stringWithString: s[0]]; [s[1] appendString: OF_PATH_DELIMITER_STRING]; is = [stringClass stringWithString: s[1]]; [s[1] appendString: @"baz"]; TEST(@"-[stringByAppendingPathComponent:]", [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] && [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]]) s[0] = [mutableStringClass stringWithString: @"foo"]; [s[0] appendString: @"/"]; [s[0] appendString: @"bar"]; s[1] = [mutableStringClass stringWithString: s[0]]; [s[1] appendString: @"/"]; is = [stringClass stringWithString: s[1]]; | > > | 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | TEST(@"-[stringByAppendingString:]", [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"]) TEST(@"-[stringByPrependingString:]", [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"]) #ifdef OF_HAVE_FILES s[0] = [mutableStringClass stringWithString: @"foo"]; [s[0] appendString: OF_PATH_DELIMITER_STRING]; [s[0] appendString: @"bar"]; s[1] = [mutableStringClass stringWithString: s[0]]; [s[1] appendString: OF_PATH_DELIMITER_STRING]; is = [stringClass stringWithString: s[1]]; [s[1] appendString: @"baz"]; TEST(@"-[stringByAppendingPathComponent:]", [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] && [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]]) #endif s[0] = [mutableStringClass stringWithString: @"foo"]; [s[0] appendString: @"/"]; [s[0] appendString: @"bar"]; s[1] = [mutableStringClass stringWithString: s[0]]; [s[1] appendString: @"/"]; is = [stringClass stringWithString: s[1]]; |
︙ | ︙ | |||
596 597 598 599 600 601 602 | componentsSeparatedByString: @"XX" options: OF_STRING_SKIP_EMPTY]) && [a count] == 3 && [[a objectAtIndex: i++] isEqual: @"foo"] && [[a objectAtIndex: i++] isEqual: @"bar"] && [[a objectAtIndex: i++] isEqual: @"baz"]) | > | | | | | | | 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | componentsSeparatedByString: @"XX" options: OF_STRING_SKIP_EMPTY]) && [a count] == 3 && [[a objectAtIndex: i++] isEqual: @"foo"] && [[a objectAtIndex: i++] isEqual: @"bar"] && [[a objectAtIndex: i++] isEqual: @"baz"]) #ifdef OF_HAVE_FILES # if !defined(OF_WINDOWS) && !defined(OF_MSDOS) # define EXPECTED @"foo/bar/baz" # else # define EXPECTED @"foo\\bar\\baz" # endif TEST(@"+[pathWithComponents:]", (is = [stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil]]) && [is isEqual: EXPECTED] && (is = [stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", nil]]) && [is isEqual: @"foo"]) # undef EXPECTED TEST(@"-[pathComponents]", /* /tmp */ (a = [C(@"/tmp") pathComponents]) && [a count] == 2 && [[a objectAtIndex: 0] isEqual: @""] && [[a objectAtIndex: 1] isEqual: @"tmp"] && /* /tmp/ */ |
︙ | ︙ | |||
661 662 663 664 665 666 667 | [[C(@"/tmp/foo/") stringByDeletingLastPathComponent] isEqual: @"/tmp"] && [[C(@"foo/bar") stringByDeletingLastPathComponent] isEqual: @"foo"] && [[C(@"/") stringByDeletingLastPathComponent] isEqual: @"/"] && [[C(@"foo") stringByDeletingLastPathComponent] isEqual: @"."]) | | | | | | | > | 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | [[C(@"/tmp/foo/") stringByDeletingLastPathComponent] isEqual: @"/tmp"] && [[C(@"foo/bar") stringByDeletingLastPathComponent] isEqual: @"foo"] && [[C(@"/") stringByDeletingLastPathComponent] isEqual: @"/"] && [[C(@"foo") stringByDeletingLastPathComponent] isEqual: @"."]) # if !defined(OF_WINDOWS) && !defined(OF_MSDOS) # define EXPECTED @"/foo./bar" # else # define EXPECTED @"\\foo.\\bar" # endif TEST(@"-[stringByDeletingPathExtension]", [[C(@"foo.bar") stringByDeletingPathExtension] isEqual: @"foo"] && [[C(@"foo..bar") stringByDeletingPathExtension] isEqual: @"foo."] && [[C(@"/foo./bar") stringByDeletingPathExtension] isEqual: @"/foo./bar"] && [[C(@"/foo./bar.baz") stringByDeletingPathExtension] isEqual: EXPECTED] && [[C(@"foo.bar/") stringByDeletingPathExtension] isEqual: @"foo"] && [[C(@".foo") stringByDeletingPathExtension] isEqual: @".foo"] && [[C(@".foo.bar") stringByDeletingPathExtension] isEqual: @".foo"]) # undef EXPECTED #endif TEST(@"-[decimalValue]", [C(@"1234") decimalValue] == 1234 && [C(@"\r\n+123 ") decimalValue] == 123 && [C(@"-500\t") decimalValue] == -500 && [C(@"\t\t\r\n") decimalValue] == 0) |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [a9b0ea0b54] to [a633b7ccbe].
︙ | ︙ | |||
406 407 408 409 410 411 412 413 414 | [self RIPEMD160HashTests]; [self SHA1HashTests]; [self SHA224HashTests]; [self SHA256HashTests]; [self SHA384HashTests]; [self SHA512HashTests]; [self HMACTests]; [self PBKDF2Tests]; [self scryptTests]; | > | < | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | [self RIPEMD160HashTests]; [self SHA1HashTests]; [self SHA224HashTests]; [self SHA256HashTests]; [self SHA384HashTests]; [self SHA512HashTests]; [self HMACTests]; #endif [self PBKDF2Tests]; [self scryptTests]; #if defined(OF_HAVE_FILES) && defined(HAVE_CODEPAGE_437) [self INIFileTests]; #endif #ifdef OF_HAVE_SOCKETS [self TCPSocketTests]; [self UDPSocketTests]; [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS |
︙ | ︙ |