|
11 | 11 | @implementation VVEnumCommenter |
12 | 12 |
|
13 | 13 | - (NSString *)document { |
14 | | - NSString *enumDefinePattern = @"^\\s*(\\w+\\s+)?NS_ENUM.*\\{"; |
15 | | - NSString *enumPartsString = [[self.code vv_stringByReplacingRegexPattern:enumDefinePattern withString:@""] |
16 | | - vv_stringByReplacingRegexPattern:@"[}]$" withString:@""]; |
17 | | - |
18 | | - NSArray *enumParts = [enumPartsString componentsSeparatedByString:@","]; |
19 | | - |
| 14 | + //Regular comment documentation |
20 | 15 | NSString *finalString = [NSString stringWithFormat:@"%@%@%@\n", [self startComment], |
21 | 16 | [self sinceComment], |
22 | 17 | [self endComment]]; |
23 | 18 |
|
24 | | - NSRegularExpression *ex = [NSRegularExpression regularExpressionWithPattern:enumDefinePattern options:0 error:nil]; |
25 | | - NSTextCheckingResult *res = [ex firstMatchInString:self.code options:0 range:NSMakeRange(0, self.code.length)]; |
| 19 | + NSString *enumDefinePattern = @"^\\s*(\\w+\\s+)?NS_ENUM.*\\{"; |
| 20 | + |
| 21 | + NSRegularExpression *enumDefineExpression = [NSRegularExpression regularExpressionWithPattern:enumDefinePattern options:0 error:nil]; |
| 22 | + NSTextCheckingResult *enumDefineResult = [enumDefineExpression firstMatchInString:self.code options:0 range:NSMakeRange(0, self.code.length)]; |
26 | 23 |
|
27 | | - finalString = [finalString stringByAppendingString:[self.code substringWithRange:[res rangeAtIndex:0]]]; |
| 24 | + finalString = [finalString stringByAppendingString:[self.code substringWithRange:[enumDefineResult rangeAtIndex:0]]]; |
28 | 25 | finalString = [finalString stringByAppendingString:@"\n"]; |
29 | 26 |
|
| 27 | + NSString *endPattern = @"\\}\\s*;"; |
| 28 | + NSString *enumPartsString = [[self.code vv_stringByReplacingRegexPattern:enumDefinePattern withString:@""] |
| 29 | + vv_stringByReplacingRegexPattern:endPattern withString:@""]; |
| 30 | + NSArray *enumParts = [enumPartsString componentsSeparatedByString:@","]; |
| 31 | + |
30 | 32 | for (NSString *part in enumParts) { |
31 | | - NSString *temp = [NSString stringWithFormat:@"%@%@%@%@", [self startComment], |
32 | | - [self sinceComment], |
33 | | - [self endComment], |
34 | | - part]; |
35 | | - if (part != [enumParts lastObject]) { |
36 | | - temp = [temp stringByAppendingString:@",\n"]; |
| 33 | + NSLog(@"%@",part); |
| 34 | + //Only append when there is a enum define. (In case of the last comma, followed no define) |
| 35 | + if ([part stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length != 0) { |
| 36 | + NSString *temp = [NSString stringWithFormat:@"%@%@%@%@", [self startComment], |
| 37 | + [self sinceComment], |
| 38 | + [self endComment], |
| 39 | + part]; |
| 40 | + if (part != [enumParts lastObject]) { |
| 41 | + temp = [temp stringByAppendingString:@",\n"]; |
| 42 | + } |
| 43 | + NSLog(@"%@",temp); |
| 44 | + finalString = [finalString stringByAppendingString:temp]; |
37 | 45 | } |
38 | | - finalString = [finalString stringByAppendingString:temp]; |
39 | 46 | } |
40 | 47 |
|
41 | | - return finalString; |
| 48 | + return [finalString stringByAppendingString:@"};"]; |
42 | 49 | } |
43 | 50 |
|
44 | 51 | @end |
0 commit comments