Provide file promises from the mapping list. Perform various file sanitization in...
[enjoyable.git] / NSString+FixFilename.m
1 //
2 // NSString+FixFilename.m
3 // Enjoyable
4 //
5 // Created by Joe Wreschnig on 3/7/13.
6 //
7 //
8
9 #import "NSString+FixFilename.h"
10
11 @implementation NSString (FixFilename)
12
13 - (NSString *)stringByFixingPathComponent {
14 static NSCharacterSet *invalid;
15 if (!invalid)
16 invalid = [NSCharacterSet characterSetWithCharactersInString:@"/:"];
17 NSArray *parts = [self componentsSeparatedByCharactersInSet:invalid];
18 NSString *newName = [parts componentsJoinedByString:@""];
19 if (!newName.length)
20 return @"_";
21 if ([newName characterAtIndex:0] == '.')
22 newName = [@"_" stringByAppendingString:newName];
23 return newName;
24 }
25
26 @end