Provide file promises from the mapping list. Perform various file sanitization in...
[enjoyable.git] / NSString+FixFilename.m
diff --git a/NSString+FixFilename.m b/NSString+FixFilename.m
new file mode 100644 (file)
index 0000000..fc8ba57
--- /dev/null
@@ -0,0 +1,26 @@
+//
+//  NSString+FixFilename.m
+//  Enjoyable
+//
+//  Created by Joe Wreschnig on 3/7/13.
+//
+//
+
+#import "NSString+FixFilename.h"
+
+@implementation NSString (FixFilename)
+
+- (NSString *)stringByFixingPathComponent {
+    static NSCharacterSet *invalid;
+    if (!invalid)
+        invalid = [NSCharacterSet characterSetWithCharactersInString:@"/:"];
+    NSArray *parts = [self componentsSeparatedByCharactersInSet:invalid];
+    NSString *newName = [parts componentsJoinedByString:@""];
+    if (!newName.length)
+        return @"_";
+    if ([newName characterAtIndex:0] == '.')
+        newName = [@"_" stringByAppendingString:newName];
+    return newName;
+}
+
+@end