@@ -12,10 +12,14 @@ @implementation VVEnumCommenter
1212
1313- (NSString *)document {
1414 // Regular comment documentation
15- NSString *finalString = [NSString stringWithFormat: @" %@%@%@ \n " , [self startComment ],
16- [self sinceComment ],
17- [self endComment ]];
18-
15+ NSString *finalString = [NSString stringWithFormat: @" %@%@%@ " , [self startComment ],
16+ [self sinceComment ],
17+ [self endComment ]];
18+
19+ if (![finalString hasSuffix: @" \n " ]) {
20+ finalString = [finalString stringByAppendingString: @" \n " ];
21+ }
22+
1923 // Grab everything from the start of the line to the opening brace, which
2024 // may be on a different line.
2125 NSString *enumDefinePattern = @" ^\\ s*(\\ w+\\ s+)?NS_(ENUM|OPTIONS)[\\ s\\ S]*?\\ {" ;
@@ -32,14 +36,28 @@ - (NSString *)document {
3236 NSArray *enumParts = [enumPartsString componentsSeparatedByString: @" ," ];
3337
3438 for (NSString *part in enumParts) {
39+ NSString *trimmedPart = [part stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]];
3540 // Only append when there is a enum define. (In case of the last comma, followed no define)
36- if ([part stringByTrimmingCharactersInSet: [ NSCharacterSet whitespaceAndNewlineCharacterSet ]] .length != 0 ) {
37- NSString *temp = [NSString stringWithFormat: @" %@%@%@%@ " , [self startComment ],
41+ if (trimmedPart .length != 0 ) {
42+ NSString *temp = [NSString stringWithFormat: @" %@%@%@ " , [self startComment ],
3843 [self sinceComment ],
39- [self endComment ],
40- part];
44+ [self endComment ]];
45+
46+ if ([temp hasSuffix: @" \n " ]) {
47+ // comment has a newline suffix, so trimmedPart will go on
48+ // the next line
49+ temp = [temp stringByAppendingString: trimmedPart];
50+ } else {
51+ // comment does not have a newline suffix, so trimmedPart
52+ // needs to be moved to the next line
53+ temp = [temp stringByAppendingFormat: @" \n %@ " , trimmedPart];
54+ }
55+
4156 if (part != [enumParts lastObject ]) {
4257 temp = [temp stringByAppendingString: @" ,\n " ];
58+ } else {
59+ // since trimmedPart was used there is no trailing newline
60+ temp = [temp stringByAppendingString: @" \n " ];
4361 }
4462 finalString = [finalString stringByAppendingString: temp];
4563 }
0 commit comments