-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathNSCharacterSet+SSYMoreCS.m
81 lines (67 loc) · 2.77 KB
/
NSCharacterSet+SSYMoreCS.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#import "NSCharacterSet+SSYMoreCS.h"
/* TODO: Test and see if the following performance optimization has any effect.
If so, consider doing it for the other class methods in here. */
static NSCharacterSet* static_zeroWidthAndIllegalCharacterSet = nil;
@implementation NSCharacterSet (SSYMoreCS)
+ (NSCharacterSet*)printingAsciiCharacterSet {
return [NSCharacterSet characterSetWithRange:NSMakeRange(0x21, 0x5f)] ;
}
+ (NSCharacterSet*)filenameLegalUnixCharacterSet {
NSMutableCharacterSet* set = [[self printingAsciiCharacterSet] mutableCopy] ;
// Remove the forward slash character
[set removeCharactersInRange:NSMakeRange(0x2f, 1)] ;
NSCharacterSet* answer = [set copy] ;
#if !__has_feature(objc_arc)
[set release];
[answer autorelease];
#endif
return answer;
}
+ (NSCharacterSet*)filenameLegalMacUnixCharacterSet {
NSMutableCharacterSet* set = [[self filenameLegalUnixCharacterSet] mutableCopy] ;
// Remove the forward slash character
[set removeCharactersInRange:NSMakeRange(0x3a, 1)] ;
[set addCharactersInString:@" "] ;
NSCharacterSet* answer = [set copy] ;
#if !__has_feature(objc_arc)
[set release];
[answer autorelease];
#endif
return answer;
}
- (NSString*)stringOfAllCharacters {
NSInteger i ;
NSMutableString* string = [[NSMutableString alloc] init] ;
for (i=0; i<0x10000; i++) {
if ([[NSCharacterSet filenameLegalMacUnixCharacterSet] characterIsMember:(unichar)i]) {
[string appendFormat:@"%c", (unichar)i] ;
}
}
NSString* answer = [string copy];
#if !__has_feature(objc_arc)
[answer autorelease];
#endif
return answer;
}
+ (NSCharacterSet*)characterSetNotAllowedInUrlHost {
return [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyz0123456789.-_"] invertedSet] ;
}
+ (NSCharacterSet*)ssyUsaKeyboardCharacterSet {
return [NSCharacterSet characterSetWithCharactersInString:@"\r\t\n !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"] ;
}
+ (NSCharacterSet*)ssyHexDigitsCharacterSet {
return [NSCharacterSet characterSetWithCharactersInString:@"abcdefABCDEF0123456789"] ;
}
+ (NSCharacterSet*)zeroWidthAndIllegalCharacterSet {
if (!static_zeroWidthAndIllegalCharacterSet) {
NSMutableCharacterSet* zeroWidthAndIllegalCharacterSet = [[NSCharacterSet controlCharacterSet] mutableCopy];
[zeroWidthAndIllegalCharacterSet formIntersectionWithCharacterSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet]];
[zeroWidthAndIllegalCharacterSet formUnionWithCharacterSet:[NSCharacterSet illegalCharacterSet]];
static_zeroWidthAndIllegalCharacterSet = [zeroWidthAndIllegalCharacterSet copy];
#if !__has_feature(objc_arc)
[zeroWidthAndIllegalCharacterSet release];
#endif
}
return static_zeroWidthAndIllegalCharacterSet;
}
@end