Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Unified Diff: class-dump/src/CDBalanceFormatter.m

Issue 7793008: Add the 3.3.3 sources for class-dump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « class-dump/src/CDBalanceFormatter.h ('k') | class-dump/src/CDClassDump.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: class-dump/src/CDBalanceFormatter.m
===================================================================
--- class-dump/src/CDBalanceFormatter.m (revision 0)
+++ class-dump/src/CDBalanceFormatter.m (revision 0)
@@ -0,0 +1,107 @@
+// -*- mode: ObjC -*-
+
+// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
+// Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard.
+
+#import "CDBalanceFormatter.h"
+
+#import "NSString-Extensions.h"
+
+static BOOL debug = NO;
+
+@implementation CDBalanceFormatter
+
+- (id)initWithString:(NSString *)str;
+{
+ if ([super init] == nil)
+ return nil;
+
+ scanner = [[NSScanner alloc] initWithString:str];
+ openCloseSet = [[NSCharacterSet characterSetWithCharactersInString:@"{}<>()"] retain];
+
+ result = [[NSMutableString alloc] init];
+
+ return self;
+}
+
+- (void)dealloc;
+{
+ [scanner release];
+ [openCloseSet release];
+
+ [result release];
+
+ [super dealloc];
+}
+
+- (void)parse:(NSString *)open index:(NSUInteger)openIndex level:(NSUInteger)level;
+{
+ NSArray *pairs;
+ NSString *pre;
+ NSString *opens[] = { @"{", @"<", @"(", nil};
+ NSString *closes[] = { @"}", @">", @")", nil};
+ NSUInteger index;
+ BOOL foundOpen = NO;
+ BOOL foundClose = NO;
+
+ pairs = [[NSArray alloc] initWithObjects:@"{}", @"<>", @"()", nil];
+
+ while ([scanner isAtEnd] == NO) {
+ if ([scanner scanUpToCharactersFromSet:openCloseSet intoString:&pre]) {
+ if (debug) NSLog(@"pre = '%@'", pre);
+ [result appendFormat:@"%@%@\n", [NSString spacesIndentedToLevel:level], pre];
+ }
+ if (debug) NSLog(@"remaining: '%@'", [[scanner string] substringFromIndex:[scanner scanLocation]]);
+
+ foundOpen = foundClose = NO;
+ for (index = 0; index < 3; index++) {
+ if (debug) NSLog(@"Checking open %u: '%@'", index, opens[index]);
+ if ([scanner scanString:opens[index] intoString:NULL]) {
+ if (debug) NSLog(@"Start %@", opens[index]);
+ [result appendSpacesIndentedToLevel:level];
+ [result appendString:opens[index]];
+ [result appendString:@"\n"];
+
+ [self parse:opens[index] index:[scanner scanLocation] - 1 level:level + 1];
+
+ [result appendSpacesIndentedToLevel:level];
+ [result appendString:closes[index]];
+ [result appendString:@"\n"];
+ foundOpen = YES;
+ break;
+ }
+
+ if (debug) NSLog(@"Checking close %u: '%@'", index, closes[index]);
+ if ([scanner scanString:closes[index] intoString:NULL]) {
+ if ([open isEqualToString:opens[index]]) {
+ if (debug) NSLog(@"End %@", closes[index]);
+ } else {
+ NSLog(@"ERROR: Unmatched end %@", closes[index]);
+ }
+ foundClose = YES;
+ break;
+ }
+ }
+
+ if (foundOpen == NO && foundClose == NO) {
+ if (debug) NSLog(@"Unknown @ %u: %@", [scanner scanLocation], [[scanner string] substringFromIndex:[scanner scanLocation]]);
+ break;
+ }
+
+ if (foundClose)
+ break;
+ }
+
+ [pairs release];
+}
+
+- (NSString *)format;
+{
+ [self parse:nil index:0 level:0];
+
+ if (debug) NSLog(@"result:\n%@", result);
+
+ return [NSString stringWithString:result];
+}
+
+@end
Property changes on: class-dump/src/CDBalanceFormatter.m
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « class-dump/src/CDBalanceFormatter.h ('k') | class-dump/src/CDClassDump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698