@@ -103,7 +103,7 @@ - (void) showFile
103
103
if (startFile==@" fileview" ){
104
104
fileTxt=[file textContents: &theError];
105
105
if (!theError)
106
- fileTxt=[self parseHTML: fileTxt];
106
+ fileTxt=[GLFileView parseHTML: fileTxt];
107
107
}else if (startFile==@" blame" ){
108
108
fileTxt=[file blame: &theError];
109
109
if (!theError)
@@ -113,7 +113,7 @@ - (void) showFile
113
113
}else if (startFile==@" diff" ){
114
114
fileTxt=[file diff: diffType error: &theError];
115
115
if (!theError)
116
- fileTxt=[self parseDiff: fileTxt];
116
+ fileTxt=[GLFileView parseDiff: fileTxt];
117
117
}
118
118
119
119
id script = [view windowScriptObject ];
@@ -214,7 +214,7 @@ - (void)closeView
214
214
[super closeView ];
215
215
}
216
216
217
- - (NSString *) parseHTML : (NSString *)txt
217
+ + (NSString *) parseHTML : (NSString *)txt
218
218
{
219
219
txt=[txt stringByReplacingOccurrencesOfString: @" &" withString: @" &" ];
220
220
txt=[txt stringByReplacingOccurrencesOfString: @" <" withString: @" <" ];
@@ -223,23 +223,21 @@ - (NSString *) parseHTML:(NSString *)txt
223
223
return txt;
224
224
}
225
225
226
- - (NSString *) parseDiff : (NSString *)txt
226
+ + (NSString *) parseDiff : (NSString *)txt
227
227
{
228
228
txt=[self parseHTML: txt];
229
229
230
230
NSArray *lines = [txt componentsSeparatedByString: @" \n " ];
231
231
NSString *line;
232
232
NSMutableString *res=[NSMutableString string ];
233
-
234
- [res appendString: @" <table class='diff'><thead><tr><td colspan='3'>" ];
233
+ BOOL inDiff=FALSE ;
235
234
int i=0 ;
235
+ line=[lines objectAtIndex: i++];
236
236
while (i<[lines count ]){
237
- line=[lines objectAtIndex: i];
238
- if ([[line substringToIndex: 2 ] isEqualToString: @" @@" ]){
239
- [res appendString: @" </td></tr></thead><tbody>" ];
237
+ if ([GLFileView isStartBlock: line]){
240
238
241
- int l_int,l_count, l_line;
242
- int r_int,r_count, r_line;
239
+ int l_int,l_line,l_end ;
240
+ int r_int,r_line,r_end ;
243
241
244
242
NSString *header=[line substringFromIndex: 3 ];
245
243
NSRange hr = NSMakeRange (0 , [header rangeOfString: @" @@" ].location );
@@ -248,15 +246,17 @@ - (NSString *) parseDiff:(NSString *)txt
248
246
NSArray *pos=[header componentsSeparatedByString: @" " ];
249
247
NSArray *pos_l=[[pos objectAtIndex: 0 ] componentsSeparatedByString: @" ," ];
250
248
NSArray *pos_r=[[pos objectAtIndex: 1 ] componentsSeparatedByString: @" ," ];
249
+
251
250
l_line=l_int=abs ([[pos_l objectAtIndex: 0 ]integerValue]);
252
- l_count=[[pos_l objectAtIndex: 1 ]integerValue];
251
+ l_end=l_line+[[pos_l objectAtIndex: 1 ]integerValue];
252
+
253
253
r_line=r_int=[[pos_r objectAtIndex: 0 ]integerValue];
254
- r_count= [[pos_r objectAtIndex: 1 ]integerValue];
254
+ r_end=r_line+ [[pos_r objectAtIndex: 1 ]integerValue];
255
255
256
256
[res appendString: [NSString stringWithFormat: @" <tr class='header'><td colspan='3'>%@ </td></tr>" ,line]];
257
257
258
258
do {
259
- line=[lines objectAtIndex: ++i ];
259
+ line=[lines objectAtIndex: i++ ];
260
260
NSString *s=[line substringToIndex: 1 ];
261
261
262
262
if ([s isEqualToString: @" " ]){
@@ -266,21 +266,42 @@ - (NSString *) parseDiff:(NSString *)txt
266
266
}else if ([s isEqualToString: @" +" ]){
267
267
[res appendString: [NSString stringWithFormat: @" <tr class='r'><td class='l'></td><td class='r'>%d </td>" ,r_line++]];
268
268
}
269
- [res appendString: [NSString stringWithFormat: @" <td class='code'>%@ </td></tr>" ,line]];
270
- }while (l_line<(l_int+l_count) && r_line<(r_int+r_count));
271
-
269
+ [res appendString: [NSString stringWithFormat: @" <td class='code'>%@ </td></tr>" ,line]];
270
+ // NSLog(@"%@ %d(%d)-%d(%d)",s,l_line,(l_int+l_count),r_line,(r_int+r_count));
271
+ }while ((l_line<l_end) || (r_line<r_end));
272
+
273
+ }else if ([GLFileView isStartDiff: line]){
274
+ if (inDiff)
275
+ [res appendString: @" </tbody></table>" ];
276
+ inDiff=TRUE ;
277
+ [res appendString: @" <table class='diff'><thead><tr><td colspan='3'>" ];
278
+ do {
279
+ [res appendString: [NSString stringWithFormat: @" <p>%@ </p>" ,line]];
280
+ line=[lines objectAtIndex: i++];
281
+ }while (![GLFileView isStartBlock: line]);
282
+ [res appendString: @" </td></tr></thead><tbody>" ];
272
283
}else {
273
- [res appendString: [ NSString stringWithFormat: @" <p> %@ </p> " ,line]];
284
+ line=[lines objectAtIndex: i++];
274
285
}
275
- i++;
276
286
}
277
- [res appendString: @" </tbody></table>" ];
287
+ if (inDiff)
288
+ [res appendString: @" </tbody></table>" ];
278
289
return res;
279
290
}
280
291
292
+ +(BOOL )isStartDiff : (NSString *)line
293
+ {
294
+ return (([line length ]>10 ) && [[line substringToIndex: 10 ] isEqualToString: @" diff --git" ]);
295
+ }
296
+
297
+ +(BOOL )isStartBlock : (NSString *)line
298
+ {
299
+ return (([line length ]>2 ) && [[line substringToIndex: 2 ] isEqualToString: @" @@" ]);
300
+ }
301
+
281
302
- (NSString *) parseBlame : (NSString *)txt
282
303
{
283
- txt=[self parseHTML: txt];
304
+ txt=[GLFileView parseHTML: txt];
284
305
285
306
NSArray *lines = [txt componentsSeparatedByString: @" \n " ];
286
307
NSString *line;
0 commit comments