Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tidy

  • Loading branch information...
commit db65712bd76aa3411cd2730c79c57970e8c6772a 1 parent b86bdd3
@mikeabdullah mikeabdullah authored
Showing with 46 additions and 44 deletions.
  1. +5 −6 KSPathUtilities.h
  2. +41 −38 KSPathUtilities.m
View
11 KSPathUtilities.h
@@ -29,10 +29,6 @@
@interface NSString (KSPathUtilities)
-// Standardizes the paths and tests equality ignoring case
-- (BOOL)ks_isEqualToPath:(NSString *)aPath;
-
-
#pragma mark Path Suffix
// 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
@@ -44,11 +40,14 @@
#pragma mark Comparing Paths
-// Will preserve any trailing slashes that are part of self
-- (NSString *)ks_pathRelativeToDirectory:(NSString *)otherPath;
+// Standardizes the paths and tests equality ignoring case
+- (BOOL)ks_isEqualToPath:(NSString *)aPath;
- (BOOL)ks_isSubpathOfPath:(NSString *)aPath; // Does aPath contain self?
+// Will preserve any trailing slashes that are part of self
+- (NSString *)ks_pathRelativeToDirectory:(NSString *)otherPath;
+
#pragma mark POSIX Paths
View
79 KSPathUtilities.m
@@ -44,15 +44,6 @@ - (id)initWithBasePath:(NSString *)basePath suffix:(NSUInteger)suffix;
@implementation NSString (KSPathUtilities)
-- (BOOL)ks_isEqualToPath:(NSString *)aPath;
-{
- NSString *myPath = [self stringByStandardizingPath];
- aPath = [aPath stringByStandardizingPath];
-
- BOOL result = ([myPath caseInsensitiveCompare:aPath] == NSOrderedSame);
- return result;
-}
-
#pragma mark Path Suffix
- (NSString *)ks_stringWithPathSuffix:(NSString *)aString;
@@ -80,6 +71,46 @@ - (NSString *)ks_stringByIncrementingPath;
return [[[KSIncrementedPath alloc] initWithBasePath:self suffix:2] autorelease];
}
+#pragma mark Comparing Paths
+
+- (BOOL)ks_isEqualToPath:(NSString *)aPath;
+{
+ NSString *myPath = [self stringByStandardizingPath];
+ aPath = [aPath stringByStandardizingPath];
+
+ BOOL result = ([myPath caseInsensitiveCompare:aPath] == NSOrderedSame);
+ return result;
+}
+
+/* We can somewhat cheat by giving each path a trailing slash and then do simple string comparison.
+ That way we ensure that we don't have something like ABCDEFGH being considered a subpath of ABCD
+ But ABCD/EFGH will be.
+ */
+- (BOOL)ks_isSubpathOfPath:(NSString *)aPath
+{
+ NSParameterAssert(aPath); // karelia case #115844
+
+
+ NSString *adjustedMePath = self;
+ if (![adjustedMePath isEqualToString:@"/"])
+ {
+ adjustedMePath = [adjustedMePath stringByAppendingString:@"/"];
+ }
+
+ NSString *adjustedOtherPath = aPath;
+ if (![adjustedOtherPath isEqualToString:@"/"])
+ {
+ adjustedOtherPath = [adjustedOtherPath stringByAppendingString:@"/"];
+ }
+
+ // Used to -hasPrefix:, but really need to do it case insensitively
+ NSRange result = [adjustedMePath rangeOfString:adjustedOtherPath
+ options:(NSAnchoredSearch | NSCaseInsensitiveSearch)];
+
+ return (result.location == 0);
+}
+
+
- (NSString *)ks_pathRelativeToDirectory:(NSString *)dirPath
{
if ([dirPath isAbsolutePath])
@@ -172,35 +203,7 @@ - (NSString *)ks_pathRelativeToDirectory:(NSString *)dirPath
return result;
}
-
-/* We can somewhat cheat by giving each path a trailing slash and then do simple string comparison.
- That way we ensure that we don't have something like ABCDEFGH being considered a subpath of ABCD
- But ABCD/EFGH will be.
- */
-- (BOOL)ks_isSubpathOfPath:(NSString *)aPath
-{
- NSParameterAssert(aPath); // karelia case #115844
-
-
- NSString *adjustedMePath = self;
- if (![adjustedMePath isEqualToString:@"/"])
- {
- adjustedMePath = [adjustedMePath stringByAppendingString:@"/"];
- }
-
- NSString *adjustedOtherPath = aPath;
- if (![adjustedOtherPath isEqualToString:@"/"])
- {
- adjustedOtherPath = [adjustedOtherPath stringByAppendingString:@"/"];
- }
-
- // Used to -hasPrefix:, but really need to do it case insensitively
- NSRange result = [adjustedMePath rangeOfString:adjustedOtherPath
- options:(NSAnchoredSearch | NSCaseInsensitiveSearch)];
-
- return (result.location == 0);
-}
-
+#pragma mark POSIX
/* Trailing slashes are insignificant under the POSIX standard. If the receiver has a trailing
* slash, a new string is returned with the slash removed.
Please sign in to comment.
Something went wrong with that request. Please try again.