forked from powerli/InstrumentsParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.m
More file actions
executable file
·107 lines (80 loc) · 2.9 KB
/
Utils.m
File metadata and controls
executable file
·107 lines (80 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// main.m
// InstrumentsParser
//
// Created by pantengfei on 14-7-29.
// Copyright (c) 2014年 ___bidu___. All rights reserved.
//
#import "Utils.h"
@implementation NSString (TrimmingAdditions)
- (NSString *)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet *)characterSet {
NSUInteger location = 0;
NSUInteger length = [self length];
unichar charBuffer[length];
[self getCharacters:charBuffer];
for (location; location < length; location++) {
if (![characterSet characterIsMember:charBuffer[location]]) {
break;
}
}
return [self substringWithRange:NSMakeRange(location, length - location)];
}
- (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet {
NSUInteger location = 0;
NSUInteger length = [self length];
unichar charBuffer[length];
[self getCharacters:charBuffer];
for (length; length > 0; length--) {
if (![characterSet characterIsMember:charBuffer[length - 1]]) {
break;
}
}
return [self substringWithRange:NSMakeRange(location, length - location)];
}
@end
@implementation Utils
+ (NSString *)unzipFile:(NSString *)filePath {
// Unzip file
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/unzip"];
NSArray *arguments;
arguments = @[@"-o", filePath];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSRange startRange = [string rangeOfString:@"inflating: "];
if (startRange.location == NSNotFound) {
return ZIP_FAILED;
}
NSString *unzipedFile = [[string substringFromIndex:(startRange.location + startRange.length)] stringByTrimmingTrailingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//printf ("\nunzip trace file:\n%s\n", [string UTF8String]);
return unzipedFile;
}
+ (BOOL) grepFile:(NSString *)filePath searchKeyword:(NSString *)keyword{
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/grep"];
NSArray *arguments = [NSArray arrayWithObjects: keyword, filePath,nil];
[task setArguments:arguments];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
NSFileHandle *file = [pipe fileHandleForReading];
[task launch];
NSData *data = [file readDataToEndOfFile];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSRange startRange = [string rangeOfString:@"matches"];
if(startRange.location == NSNotFound){
return NO;
}else{
return YES;
}
}
@end