Permalink
Browse files

-ks_stringWithPathSuffix:

  • Loading branch information...
1 parent a0974fe commit d99eb48e5ad2c7d65e10f7a30301706fd48ea210 @mikeabdullah mikeabdullah committed Nov 23, 2010
Showing with 19 additions and 0 deletions.
  1. +3 −0 KSPathUtilities.h
  2. +16 −0 KSPathUtilities.m
View
@@ -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;
View
@@ -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

0 comments on commit d99eb48

Please sign in to comment.