Overview
Comment: | Add -[OFString pathExtension]. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
37dc5d933ff30b647c57e1011f90d55b |
User & Date: | js on 2013-08-25 21:16:08 |
Other Links: | manifest | tags |
Context
2013-09-15
| ||
18:51 | OFAutoreleasePool: Free pool cache on thread exit. check-in: 29e4d00225 user: js tags: trunk | |
2013-08-25
| ||
21:16 | Add -[OFString pathExtension]. check-in: 37dc5d933f user: js tags: trunk | |
20:59 | Add -[OFString stringByDeletingPathExtension]. check-in: 0222de872b user: js tags: trunk | |
Changes
Modified src/OFString.h from [2d8cbb5422] to [71ed97918e].
︙ | ︙ | |||
871 872 873 874 875 876 877 878 879 880 881 882 883 884 | /*! * @brief Returns the last component of the path. * * @return The last component of the path */ - (OFString*)lastPathComponent; /*! * @brief Returns the directory name of the path. * * @return The directory name of the path */ - (OFString*)stringByDeletingLastPathComponent; | > > > > > > > | 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 | /*! * @brief Returns the last component of the path. * * @return The last component of the path */ - (OFString*)lastPathComponent; /*! * @brief Returns the file extension of the path. * * @return The file extension of the path */ - (OFString*)pathExtension; /*! * @brief Returns the directory name of the path. * * @return The directory name of the path */ - (OFString*)stringByDeletingLastPathComponent; |
︙ | ︙ |
Modified src/OFString.m from [9aca46e7ea] to [08f92f7b9f].
︙ | ︙ | |||
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 | * removed, so return a new string anyway. */ if (i < 0) i = 0; return [self substringWithRange: of_range(i, length - i)]; } - (OFString*)stringByDeletingLastPathComponent { void *pool; const of_unichar_t *characters; size_t i, length = [self length]; | > > > > > > > > > > > > > > > > > > > > | 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 | * removed, so return a new string anyway. */ if (i < 0) i = 0; return [self substringWithRange: of_range(i, length - i)]; } - (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) return @""; ret = [fileName substringWithRange: of_range(pos + 1, [fileName length] - pos - 1)]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString*)stringByDeletingLastPathComponent { void *pool; const of_unichar_t *characters; size_t i, length = [self length]; |
︙ | ︙ | |||
2170 2171 2172 2173 2174 2175 2176 | [components replaceObjectAtIndex: [components count] - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); | < | 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 | [components replaceObjectAtIndex: [components count] - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString*)stringByStandardizingPath { return standardize_path([self pathComponents], OF_PATH_CURRENT_DIRECTORY, OF_PATH_PARENT_DIRECTORY, |
︙ | ︙ |
Modified tests/OFStringTests.m from [c46f51d6d5] to [b0a9478f37].
︙ | ︙ | |||
325 326 327 328 329 330 331 332 333 334 335 336 337 338 | [[@"/tmp" lastPathComponent] isEqual: @"tmp"] && [[@"/tmp/" lastPathComponent] isEqual: @"tmp"] && [[@"/" lastPathComponent] isEqual: @""] && [[@"foo" lastPathComponent] isEqual: @"foo"] && [[@"foo/bar" lastPathComponent] isEqual: @"bar"] && [[@"foo/bar/baz/" lastPathComponent] isEqual: @"baz"]) TEST(@"-[stringByDeletingLastPathComponent]", [[@"/tmp" stringByDeletingLastPathComponent] isEqual: @"/"] && [[@"/tmp/" stringByDeletingLastPathComponent] isEqual: @"/"] && [[@"/tmp/foo/" stringByDeletingLastPathComponent] isEqual: @"/tmp"] && [[@"foo/bar" stringByDeletingLastPathComponent] isEqual: @"foo"] && [[@"/" stringByDeletingLastPathComponent] isEqual: @"/"] && | > > > > > > | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | [[@"/tmp" lastPathComponent] isEqual: @"tmp"] && [[@"/tmp/" lastPathComponent] isEqual: @"tmp"] && [[@"/" lastPathComponent] isEqual: @""] && [[@"foo" lastPathComponent] isEqual: @"foo"] && [[@"foo/bar" lastPathComponent] isEqual: @"bar"] && [[@"foo/bar/baz/" lastPathComponent] isEqual: @"baz"]) TEST(@"-[pathExtension]", [[@"foo.bar" pathExtension] isEqual: @"bar"] && [[@"foo/.bar" pathExtension] isEqual: @""] && [[@"foo/.bar.baz" pathExtension] isEqual: @"baz"] && [[@"foo/bar.baz/" pathExtension] isEqual: @"baz"]) TEST(@"-[stringByDeletingLastPathComponent]", [[@"/tmp" stringByDeletingLastPathComponent] isEqual: @"/"] && [[@"/tmp/" stringByDeletingLastPathComponent] isEqual: @"/"] && [[@"/tmp/foo/" stringByDeletingLastPathComponent] isEqual: @"/tmp"] && [[@"foo/bar" stringByDeletingLastPathComponent] isEqual: @"foo"] && [[@"/" stringByDeletingLastPathComponent] isEqual: @"/"] && |
︙ | ︙ |