Fix some coding style issues.
[enjoyable.git] / Categories / 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 NSCharacterSet (FixFilename)
12
13 + (NSCharacterSet *)invalidPathComponentCharacterSet {
14 return [NSCharacterSet characterSetWithCharactersInString:@"\"\\/:*?<>|"];
15 }
16
17 @end
18
19 @implementation NSString (FixFilename)
20
21 - (NSString *)stringByFixingPathComponent {
22 NSCharacterSet *invalid = NSCharacterSet.invalidPathComponentCharacterSet;
23 NSCharacterSet *whitespace = NSCharacterSet.whitespaceAndNewlineCharacterSet;
24 NSArray *parts = [self componentsSeparatedByCharactersInSet:invalid];
25 NSString *name = [parts componentsJoinedByString:@"_"];
26 name = [name stringByTrimmingCharactersInSet:whitespace];
27 if (!name.length)
28 return @"_";
29 unichar first = [name characterAtIndex:0];
30 if (first == '.' || first == '-')
31 name = [@"_" stringByAppendingString:name];
32 return name;
33 }
34
35 @end