Skip to content

Commit

Permalink
add: property group support comment // & /**/
Browse files Browse the repository at this point in the history
  • Loading branch information
qfish committed Dec 3, 2013
1 parent ab6df88 commit 579c1bf
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 52 deletions.
9 changes: 7 additions & 2 deletions main/main/4.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@property (nonatomic, retain) UITextField * textView;
@property (nonatomic, retain) UIButton editButton;
@property (nonatomic, assign) int editButton;
@property (nonatomic, copy) UIButton * editButton;
@property (nonatomic, assign) int editButton; ///asdasdas
@property (nonatomic, copy) UIButton * editButton;
@property (strong, nonatomic) NSString *gender;
@property (strong, nonatomic) NSString * headURL; /*sad*/
@property (strong, nonatomic) NSString * dtype; //1qq 2新浪 3游客
@property (strong, nonatoasdmic) NSString * followNums;
@property (strong, nonatomic) NSString *fanNums;
1 change: 0 additions & 1 deletion main/main/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@

- (IBAction)format:(id)sender;
- (IBAction)selectFormatter:(id)sender;
- (IBAction)showSetting:(id)sender;

@end
78 changes: 47 additions & 31 deletions main/main/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,24 @@

#import "AppDelegate.h"
#import "NSString+XAlign.h"
#import "SettingWindowController.h"
#import <CoreText/CoreText.h>

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self test1];
// [self test1];
// [self test2];
// [self test3];
// [self test4];
// [self test5];

NSArray * pgs = [XAlignPatternManager patternGroupsWithContentsOfFile:@"patterns"];
NSString * replace = [[self testFile:@"2.txt"] stringByAligningWithPatterns:pgs[1]];
NSString * replace = [[self testFile:@"4.txt"] stringByAligningWithPatterns:pgs[2]];

NSLog( @"\n%@", replace );
}

- (void)showSetting:(id)sender
{
if ( nil == self.settingWindow )
{
self.settingWindow = [[SettingWindowController alloc] initWithWindowNibName:@"SettingWindowController"];
}

[self.settingWindow showWindow:self.settingWindow];
}

- (IBAction)format:(id)sender
{
// NSString * input = self.input.string;
Expand Down Expand Up @@ -103,7 +92,7 @@ - (void)test2
p3.isOptional = YES;
p3.string = @"\\s*//.*$";
p3.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
NSLog( @"%d =%@=", padding, match);
// NSLog( @"%d =%@=", padding, match);
return [NSString stringWithFormat:@"+++|%@", match.xtrim];
};

Expand Down Expand Up @@ -163,36 +152,63 @@ - (void)test4

- (void)test5
{
XAlignPattern * p1 = [[XAlignPattern alloc] init];
p1.string = @"[\\s\\*]*\\w+";
p1.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
if ( NSNotFound == [match rangeOfString:@"*"].location )
return [NSString stringWithFormat:@" %@", match.xtrim];
return match.xtrim;
XAlignPattern * p0 = [[XAlignPattern alloc] init];
p0.string = @"^\\s*@property\\s*";
p0.tailMode = XAlignPaddingModeMax;
p0.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return @"@property ";
};

// XAlignPattern * p1 = [[XAlignPattern alloc] init];
// p1.string = @"\\(.*\\)";
// p1.matchMode = XAlignPaddingModeMax;
// p1.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
// return match.xtrim;
// };

XAlignPattern * p2 = [[XAlignPattern alloc] init];
p2.string = @"(?<=\\w)\\s*";
p2.matchMode = XAlignPaddingModeMax;
p2.string = @"(?<=\\))\\s*(?=\\w)";
p2.tailMode = XAlignPaddingModeMax;
p2.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return @" ";
};

XAlignPattern * p3 = [[XAlignPattern alloc] init];
p3.string = @"(?<=\\))\\s*(?=\\w)";
p3.tailMode = XAlignPaddingModeMax;
p3.isOptional = YES;
p3.string = @"\\s+\\*";
p3.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return @" ";
return @" *";
};

XAlignPattern * p4_1 = [[XAlignPattern alloc] init];
p4_1.isOptional = YES;
p4_1.string = @"(?<!\\*)\\s*\\w+;";
p4_1.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return [NSString stringWithFormat:@" %@", match.xtrim];
};

XAlignPattern * p4_2 = [[XAlignPattern alloc] init];
p4_2.isOptional = YES;
p4_2.string = @"(?<=\\*)\\s*\\w+;";
p4_2.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return [NSString stringWithFormat:@" %@", match.xtrim];
};

XAlignPattern * p5 = [[XAlignPattern alloc] init];
p5.isOptional = YES;
p5.string = @"\\s*//.*$";
p5.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return [NSString stringWithFormat:@" %@", match.xtrim];
};

XAlignPattern * p4 = [[XAlignPattern alloc] init];
p4.string = @"^\\s*@property\\s*";
p4.tailMode = XAlignPaddingModeMax;
p4.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return @"@property ";
XAlignPattern * p6 = [[XAlignPattern alloc] init];
p6.isOptional = YES;
p6.string = @"\\s*/\\*.*$";
p6.control = ^ NSString * ( NSUInteger padding, NSString * match ) {
return [NSString stringWithFormat:@" %@", match.xtrim];
};

NSArray * patterns = @[p4, p3, p2, p1];
NSArray * patterns = @[p0, p2, p3, p4_1, p4_2, p5, p6];

NSString * replace = [[self testFile:@"4.txt"] stringByAligningWithPatterns:patterns];

Expand Down
3 changes: 0 additions & 3 deletions main/main/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,6 @@
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="showSetting:" target="494" id="a9U-O9-UTW"/>
</connections>
</button>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rpU-Fd-yjH">
<rect key="frame" x="6" y="161" width="346" height="25"/>
Expand Down
63 changes: 53 additions & 10 deletions main/main/patterns.plist
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,73 @@
</dict>
<dict>
<key>string</key>
<string>(?&lt;=\w)\s*</string>
<key>tailMode</key>
<integer>2</integer>
<string>\s+\*</string>
<key>isOptional</key>
<true/>
<key>control</key>
<dict>
<key>string</key>
<string> </string>
<string> * </string>
</dict>
</dict>
<dict>
<key>string</key>
<string>(?&lt;!\*)\s*\w+;</string>
<key>isOptional</key>
<true/>
<key>control</key>
<dict>
<key>format</key>
<string> %@</string>
<key>needTrim</key>
<true/>
<key>needFormat</key>
<true/>
</dict>
</dict>
<dict>
<key>string</key>
<string>[\s\*]*\w+</string>
<string>(?&lt;=\*)\s*\w+;</string>
<key>isOptional</key>
<true/>
<key>control</key>
<dict>
<key>format</key>
<string>%@</string>
<key>notFoundFormat</key>
<string> %@</string>
<key>needTrim</key>
<true/>
<key>needFormatWhenFound</key>
<key>needFormat</key>
<true/>
</dict>
</dict>
<dict>
<key>string</key>
<string>\s*//.*$</string>
<key>isOptional</key>
<true/>
<key>control</key>
<dict>
<key>format</key>
<string> %@</string>
<key>needFormat</key>
<true/>
<key>needTrim</key>
<true/>
</dict>
</dict>
<dict>
<key>string</key>
<string>\s*/\*.*$</string>
<key>isOptional</key>
<true/>
<key>control</key>
<dict>
<key>format</key>
<string> %@</string>
<key>needFormat</key>
<true/>
<key>needTrim</key>
<true/>
<key>foundString</key>
<string>*</string>
</dict>
</dict>
</array>
Expand Down
5 changes: 1 addition & 4 deletions plugin/XAlign/XAlignPluginConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ + (void)setupMenu
NSString * selector = item[kMenuSelector];

if ( selector )
{
SEL action = NSSelectorFromString(selector);
menuItem.action = action;
}
menuItem.action = NSSelectorFromString(selector);;

[alignMenu addItem:menuItem];
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/XAlign/setting.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<key>shortcut</key>
<dict>
<key>key</key>
<string>a</string>
<string>x</string>
<key>mask</key>
<string>cmd+shfit</string>
</dict>
Expand Down

0 comments on commit 579c1bf

Please sign in to comment.