Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 66 lines (47 sloc) 2.845 kb
3c3d929 Four lovely methods for those of you working with paths. But let's face ...
Mike authored
1 //
2 // KSPathUtilities.h
3 //
5e343ed Dan Wood update copyrights to 2012
danwood authored
4 // Copyright (c) 2005-2012 Dan Wood, Mike Abdullah and Karelia Software
20a1855 Mike Abdullah Settle on BSD license.
mikeabdullah authored
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL DAN WOOD, MIKE ABDULLAH OR KARELIA SOFTWARE BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3c3d929 Four lovely methods for those of you working with paths. But let's face ...
Mike authored
25 //
26
27 #import <Cocoa/Cocoa.h>
28
29
30 @interface NSString (KSPathUtilities)
31
2e86e85 Mike Abdullah +[NSString ks_stringWithPath:relativeToDirectory:]
mikeabdullah authored
32 #pragma mark Making Paths
33 + (NSString *)ks_stringWithPath:(NSString *)path relativeToDirectory:(NSString *)directory;
34
35
b86bdd3 Mike Abdullah -[NSString ks_stringByIncrementingPath]
mikeabdullah authored
36 #pragma mark Path Suffix
37
38 // Given a path "foo/bar.png", adjusts it to be "foo/bar-2.png". Calling -ks_stringByIncrementingPath on that string will then give "foo/bar-3.png" and so on
e24f5b6 Mike Abdullah Link to -ks_stringByIncrementingPath blog post
mikeabdullah authored
39 // More at http://www.mikeabdullah.net/incrementing-paths.html
b86bdd3 Mike Abdullah -[NSString ks_stringByIncrementingPath]
mikeabdullah authored
40 - (NSString *)ks_stringByIncrementingPath;
41
d99eb48 Mike Abdullah -ks_stringWithPathSuffix:
mikeabdullah authored
42 // like -stringByAppendingString: but inserts the suffix string in front of path extension if there is one. e.g. [@"foo.png" ks_stringWithPathSuffix:@"-2"] = @"foo-2.png"
43 - (NSString *)ks_stringWithPathSuffix:(NSString *)aString;
44
b86bdd3 Mike Abdullah -[NSString ks_stringByIncrementingPath]
mikeabdullah authored
45
46 #pragma mark Comparing Paths
47
db65712 Mike Abdullah tidy
mikeabdullah authored
48 // Standardizes the paths and tests equality ignoring case
49 - (BOOL)ks_isEqualToPath:(NSString *)aPath;
b64a274 Document trailing-slash preservation behaviour.
Mike authored
50
3c3d929 Four lovely methods for those of you working with paths. But let's face ...
Mike authored
51 - (BOOL)ks_isSubpathOfPath:(NSString *)aPath; // Does aPath contain self?
52
db65712 Mike Abdullah tidy
mikeabdullah authored
53 // Will preserve any trailing slashes that are part of self
54 - (NSString *)ks_pathRelativeToDirectory:(NSString *)otherPath;
55
b86bdd3 Mike Abdullah -[NSString ks_stringByIncrementingPath]
mikeabdullah authored
56
57 #pragma mark POSIX Paths
58
3c3d929 Four lovely methods for those of you working with paths. But let's face ...
Mike authored
59 // NSString has built-in methods for standardizing a path, but they consult the filesystem for symlinks. This method only looks at the path itself
60 - (NSString *)ks_standardizedPOSIXPath;
61
62 // Like -isEqualToString: but ignores trailing slashes
63 - (BOOL)ks_isEqualToPOSIXPath:(NSString *)otherPath;
64
65 @end
Something went wrong with that request. Please try again.