Skip to content

Commit 81a2496

Browse files
ZXZX
ZX
authored and
ZX
committed
修改模板文件替换
1 parent 0cc77d8 commit 81a2496

File tree

10 files changed

+53
-44
lines changed

10 files changed

+53
-44
lines changed

Diff for: .DS_Store

0 Bytes
Binary file not shown.

Diff for: ZXCodeCreater.xcodeproj/xcuserdata/zx.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

+12-28
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,12 @@
4242
ignoreCount = "0"
4343
continueAfterRunningActions = "No"
4444
filePath = "ZXCodeCreater/ViewController.m"
45-
timestampString = "520091533.82132"
45+
timestampString = "520163888.509538"
4646
startingColumnNumber = "9223372036854775807"
4747
endingColumnNumber = "9223372036854775807"
48-
startingLineNumber = "192"
49-
endingLineNumber = "192"
50-
landmarkName = "-creatFolderAndFileAtModuleFilePath:"
51-
landmarkType = "7">
52-
</BreakpointContent>
53-
</BreakpointProxy>
54-
<BreakpointProxy
55-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
56-
<BreakpointContent
57-
shouldBeEnabled = "Yes"
58-
ignoreCount = "0"
59-
continueAfterRunningActions = "No"
60-
filePath = "ZXCodeCreater/ViewController.m"
61-
timestampString = "520091533.82132"
62-
startingColumnNumber = "9223372036854775807"
63-
endingColumnNumber = "9223372036854775807"
64-
startingLineNumber = "193"
65-
endingLineNumber = "193"
66-
landmarkName = "-creatFolderAndFileAtModuleFilePath:"
48+
startingLineNumber = "102"
49+
endingLineNumber = "102"
50+
landmarkName = "-firstCreateBtnAction:"
6751
landmarkType = "7">
6852
</BreakpointContent>
6953
</BreakpointProxy>
@@ -74,11 +58,11 @@
7458
ignoreCount = "0"
7559
continueAfterRunningActions = "No"
7660
filePath = "ZXCodeCreater/ViewController.m"
77-
timestampString = "520091555.321468"
61+
timestampString = "520163888.509538"
7862
startingColumnNumber = "9223372036854775807"
7963
endingColumnNumber = "9223372036854775807"
80-
startingLineNumber = "106"
81-
endingLineNumber = "106"
64+
startingLineNumber = "100"
65+
endingLineNumber = "100"
8266
landmarkName = "-firstCreateBtnAction:"
8367
landmarkType = "7">
8468
</BreakpointContent>
@@ -89,13 +73,13 @@
8973
shouldBeEnabled = "Yes"
9074
ignoreCount = "0"
9175
continueAfterRunningActions = "No"
92-
filePath = "ZXCodeCreater/ViewController.m"
93-
timestampString = "520091558.361684"
76+
filePath = "ZXCodeCreater/Ulits/FileManager.m"
77+
timestampString = "520159474.645428"
9478
startingColumnNumber = "9223372036854775807"
9579
endingColumnNumber = "9223372036854775807"
96-
startingLineNumber = "104"
97-
endingLineNumber = "104"
98-
landmarkName = "-firstCreateBtnAction:"
80+
startingLineNumber = "80"
81+
endingLineNumber = "80"
82+
landmarkName = "-getFilePathArrWithPath:"
9983
landmarkType = "7">
10084
</BreakpointContent>
10185
</BreakpointProxy>

Diff for: ZXCodeCreater/Ulits/FileManager.m

+1-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ - (NSArray *)getFilePathArrWithPath:(NSString *)dirPath
8181
}
8282

8383

84-
- (NSString *)getDateStr{
85-
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
86-
formatter.dateFormat = @"yy/MM/dd";
87-
return [formatter stringFromDate:[NSDate date]];
88-
}
84+
8985

9086
- (NSFileManager *)fileManager
9187
{

Diff for: ZXCodeCreater/ViewController.m

+40-11
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ @interface ViewController()<NSTextViewDelegate>
2424
@property (weak) IBOutlet NSTextField *firstModuleTxf;
2525
@property (weak) IBOutlet NSTextField *firstReplacedTxf;
2626

27-
2827
@property (unsafe_unretained) IBOutlet NSTextView *secondModulePathTxv;
2928
@property (weak) IBOutlet NSTextField *secondModuleTxf;
3029
@property (weak) IBOutlet NSTextField *secondReplacedTxf;
3130

3231

33-
34-
3532
@property (nonatomic,copy) NSString *firstFolderPathString;
3633
@property (nonatomic,copy) NSString *secondFolderPathString;
34+
3735
@property (nonatomic,copy) NSString *moduleClassPrefix;
3836
@property (nonatomic,copy) NSString *targetClassPrefix;
3937

@@ -45,11 +43,9 @@ @implementation ViewController
4543
- (void)viewDidLoad {
4644
[super viewDidLoad];
4745
[self initData];
48-
4946

5047
}
5148

52-
5349
- (void)initData
5450
{
5551
self.firstFolderPathString = [UserDefaults objectForKey:firstFolderPath];
@@ -87,7 +83,7 @@ - (IBAction)firstOpenBtnAction:(NSButton *)sender {
8783
}
8884
- (IBAction)firstCreateBtnAction:(id)sender {
8985

90-
86+
self.firstFolderPathString = self.firstModulePathTxv.string;
9187
if (!self.firstModulePathTxv.string||[self.firstModulePathTxv.string isEqualToString:@""]) {
9288

9389
[self showAlertWithMessage:@"Please select first module filePath "];
@@ -119,6 +115,10 @@ - (IBAction)secondOpenBtnAction:(NSButton *)sender {
119115
}
120116

121117
- (IBAction)secondCreateOpenBtnAction:(id)sender {
118+
119+
120+
self.secondFolderPathString = self.secondModulePathTxv.string;
121+
122122
if (!self.secondModulePathTxv.string||[self.secondModulePathTxv.string isEqualToString:@""]) {
123123

124124
[self showAlertWithMessage:@"Please select second module filePath "];
@@ -183,27 +183,56 @@ - (void)creatFolderAndFileAtModuleFilePath:(NSString *)filePath
183183
continue;
184184
}
185185
//文件夹路径;如果是文件夹的话,就创建文件夹
186-
if (![subPath containsString:@"/"]) {
186+
if (!([subPath containsString:@".h"]||[subPath containsString:@".m"])) {
187187

188188
[[FileManager sharedInstance] createFolderAtPath:newWholePath];
189189
continue;
190190
}
191191
NSString *str = [[FileManager sharedInstance] getStringWithContentsOfFilePath:wholePath];
192192
NSString *replacedStr = [str stringByReplacingOccurrencesOfString:self.moduleClassPrefix withString:self.targetClassPrefix];
193-
[[FileManager sharedInstance] createFileAtPath:newWholePath content:replacedStr];
193+
NSString *stringAfterReplaceDate = [self replaceModuleDateWithNowDate:[self getNowDateStr] nowYear:[self getNowYearStr] moduleStr:replacedStr];
194+
[[FileManager sharedInstance] createFileAtPath:newWholePath content:stringAfterReplaceDate];
194195
}
195196
[[NSWorkspace sharedWorkspace] openFile:filePath];
197+
}
198+
196199

200+
201+
#pragma mark - ReplaceDate
202+
- (NSString *)replaceModuleDateWithNowDate:(NSString *)nowDate nowYear:(NSString *)nowYear moduleStr:(NSString *)moduleStr{
203+
204+
NSMutableString *searchText = [NSMutableString stringWithFormat:@"%@",moduleStr];
205+
NSError *error = NULL;
206+
//匹配17/06/25
207+
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{1,2}/[0-9]{1,2}/[0-9]{1,2}" options:NSRegularExpressionCaseInsensitive error:&error];
208+
//匹配2017年;
209+
NSRegularExpression *regexT = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{1}[0-9]{1}[0-9]{1}[0-9]{1}[\u4e00-\u9fa5]" options:NSRegularExpressionCaseInsensitive error:&error];
210+
[regex replaceMatchesInString:searchText options:0 range:NSMakeRange(0, searchText.length) withTemplate:nowDate];
211+
[regexT replaceMatchesInString:searchText options:0 range:NSMakeRange(0, searchText.length) withTemplate:nowYear];
212+
return searchText;
213+
}
214+
215+
- (NSString *)getNowDateStr{
216+
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
217+
formatter.dateFormat = @"yy/MM/dd";
218+
return [formatter stringFromDate:[NSDate date]];
197219
}
198220

221+
- (NSString *)getNowYearStr{
222+
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
223+
formatter.dateFormat = @"yyyy";
224+
225+
NSString *nowYear = [NSString stringWithFormat:@"%@",[formatter stringFromDate:[NSDate date]]];
226+
227+
return nowYear;
228+
}
229+
230+
199231
- (void)showAlertWithMessage:(NSString *)message{
200232

201233
NSAlert *alert = [[NSAlert alloc] init];
202234
[alert setMessageText:message];
203235
[alert runModal];
204236
}
205237

206-
#pragma mark - Getter && Setter
207-
208-
209238
@end
Binary file not shown.

0 commit comments

Comments
 (0)