Skip to content

Commit

Permalink
-ks_stringWithPathSuffix:
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeabdullah committed Nov 23, 2010
1 parent a0974fe commit d99eb48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions KSPathUtilities.h
Expand Up @@ -29,6 +29,9 @@

@interface NSString (KSPathUtilities)

// 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"
- (NSString *)ks_stringWithPathSuffix:(NSString *)aString;

// Will preserve any trailing slashes that are part of self
- (NSString *)ks_pathRelativeToDirectory:(NSString *)otherPath;

Expand Down
16 changes: 16 additions & 0 deletions KSPathUtilities.m
Expand Up @@ -29,6 +29,22 @@

@implementation NSString (KSPathUtilities)

- (NSString *)ks_stringWithPathSuffix:(NSString *)aString;
{
NSString *result = self;

NSString *extension = [self pathExtension];
if ([extension length])
{
result = [[[self
stringByDeletingPathExtension]
stringByAppendingString:aString]
stringByAppendingPathExtension:extension];
}

return result;
}

- (NSString *)ks_pathRelativeToDirectory:(NSString *)dirPath
{
// Our internal workings currently expect dirPath to have a trailing slash, so let's supply that for them
Expand Down

0 comments on commit d99eb48

Please sign in to comment.