there are about 300 objectivec .m files and I need to print each file name and its method and number of lines inside the method
there is a sample perl files that do perl brace matching
www_unix_com/shell-programming-and-scripting/145336-multiline-parenthesis-matching-e-g-sed-script-latex-doc.html
now I want to convert this to count number of lines in method
perl -0ne 's/\\emph{//g;$i=0;while(/./gs){$i-- if $& eq "{";$i++ if $& eq "}"; if ($i<1){print $&}else{$i=0}}' infile > outfile
============= Sample Input =================
#import "NSArray+ObjectiveSugar.h"
#import "NSMutableArray+ObjectiveSugar.h"
#import "NSString+ObjectiveSugar.h"
static NSString * const OSMinusString = @"-";
@implementation NSArray (ObjectiveSugar)
- (id)sample {
if (self.count == 0) return nil;
NSUInteger index = arc4random_uniform((u_int32_t)self.count);
return self[index];
}
- (id)objectForKeyedSubscript:(id)key {
if ([key isKindOfClass:[NSString class]])
return [self subarrayWithRange:[self rangeFromString:key]];
else if ([key isKindOfClass:[NSValue class]])
return [self subarrayWithRange:[key rangeValue]];
else
[NSException raise:NSInvalidArgumentException format:@"expected NSString or NSValue argument, got %@ instead", [key class]];
return nil;
}
- (NSRange)rangeFromString:(NSString *)string {
NSRange range = NSRangeFromString(string);
if ([string containsString:@"..."]) {
range.length = isBackwardsRange(string) ? (self.count - 2) - range.length : range.length - range.location;
} else if ([string containsString:@".."]) {
range.length = isBackwardsRange(string) ? (self.count - 1) - range.length : range.length - range.location + 1;
}
return range;
}
=========== Sample Output==============
filename.m
- (id)sample -- 3 (line of code count)
- (id)objectForKeyedSubscript:(id)key -- 7 (line of code count)
- (NSRange)rangeFromString:(NSString *)string -- 7 (line of code count)