Commits

Jens Alfke committed 2068331

* Optimized Olivier's MYDirectoryWatcher fix (by caching the watcher's standardized path)
* Added -[NSData my_UTF8ToString] to CollectionUtils.

Comments (0)

Files changed (4)

CollectionUtils.h

 @end
 
 
+@interface NSData (MYUtils)
+- (NSString*) my_UTF8ToString;
+@end
+
+
+
 #pragma mark -
 #pragma mark FOREACH:
     

CollectionUtils.m

 
 
 
+@implementation NSData (MYUtils)
+
+- (NSString*) my_UTF8ToString {
+    return [[[NSString alloc] initWithData: self encoding: NSUTF8StringEncoding] autorelease];
+}
+
+@end
+
+
+
 #import "Test.h"
 
 TestCase(CollectionUtils) {

MYDirectoryWatcher.h

 /* A wrapper for FSEvents, which notifies its delegate when filesystem changes occur. */
 @interface MYDirectoryWatcher : NSObject 
 {
-    NSString *_path;
+    NSString *_path, *_standardizedPath;
     id _target;
     SEL _action;
     UInt64 _lastEventID;

MYDirectoryWatcher.m

     self = [super init];
     if (self != nil) {
         _path = path.copy;
+        _standardizedPath = [_path stringByStandardizingPath];
         _target = target;
         _action = action;
         _latency = 5.0;
 
 @synthesize path=_path, latency=_latency, lastEventID=_lastEventID;
 
+- (NSString*) standardizedPath {
+    return _standardizedPath;
+}
+
 
 - (BOOL) start
 {
 
 - (NSString*) relativePath
 {
-    NSString *base = [watcher.path stringByStandardizingPath];
+    NSString *base = watcher.standardizedPath;
     NSString *standardizedPath = [path stringByStandardizingPath];
     if( ! [standardizedPath hasPrefix: base] )
         return nil;