-
Notifications
You must be signed in to change notification settings - Fork 2
/
DiffLine.m
83 lines (67 loc) · 1.18 KB
/
DiffLine.m
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
//
// DiffLine.m
// SvnDiffParser
//
// Created by Matt Mower on 06/01/2007.
// Copyright 2007 Matt Mower. See MIT-LICENSE for more information.
//
#import "DiffLine.h"
#import "NSString+XMLEscape.h"
@implementation DiffLine
- (id)initWithString:(NSString *)__line
{
if( ( self = [super init] ) != nil )
{
switch( [__line characterAtIndex:0] )
{
case ' ':
[self setType:CommonLine];
break;
case '+':
[self setType:AddedLine];
break;
case '-':
[self setType:RemovedLine];
break;
}
[self setContent:__line];
}
return self;
}
- (LineType)type
{
return type;
}
- (void)setType:(LineType)__lineType
{
type = __lineType;
}
- (NSString *)content
{
return content;
}
- (void)setContent:(NSString *)__content
{
[content autorelease];
content = [__content copy];
}
- (NSString *)toHTML
{
NSString *style;
switch( type )
{
case CommonLine:
style = @"common-line";
break;
case AddedLine:
style = @"added-line";
break;
case RemovedLine:
style = @"removed-line";
break;
default:
style = @"";
}
return [NSString stringWithFormat:@"<span class='%@'>%@</span>", style, [[self content] xmlEscape]];
}
@end