-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegExLabel.m
139 lines (106 loc) · 3.01 KB
/
RegExLabel.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// RegExLabel.m
// RegExhibit
//
// Copyright 2007 Roger Jolly. All rights reserved.
//
// A RegExLabel object is a class that sits between a match and the matched text or replacement text.
// The object points towards a RegExText object which holds the beginning and ending positions of the match and the text of the replacement text.
// The RegExLabel object is only used to have an object for the outlineview.
//
#import "RegExLabel.h"
@implementation RegExLabel
#pragma mark-
#pragma mark Initialisation
- (id) init {
self = [super init];
if (self != nil) {
textOfLabel = replacementText;
containedText = [[RegExText alloc]init];
}
return self;
}
- (id) initWithBeginPosition: (int) beginPosition endPosition: (int) endPosition {
self = [super init];
if (self != nil) {
textOfLabel = matchText;
containedText = [[RegExText alloc]init];
[self setBeginPosition: beginPosition endPosition: endPosition];
}
return self;
}
- (id) initWithString: (NSString *) aString {
self = [super init];
if (self != nil) {
textOfLabel = replacementText;
containedText = [[RegExText alloc]init];
[containedText setTheText: aString];
}
return self;
}
#pragma mark-
#pragma mark Accessors
- (void) setBeginPosition: (int) beginPosition {
textOfLabel = matchText;
[containedText setBeginPosition: beginPosition];
}
- (int) beginPosition {
return [containedText beginPosition];
}
- (void) setEndPosition: (int) endPosition {
textOfLabel = matchText;
[containedText setEndPosition: endPosition];
}
- (int) endPosition {
return [containedText endPosition];
}
- (void) setBeginPosition: (int) beginPosition endPosition: (int) endPosition {
[self setBeginPosition: beginPosition];
[self setEndPosition: endPosition];
}
- (void) setTheText: (NSString *) newText {
[containedText setTheText: newText];
}
- (NSString *) theText {
return [containedText theText];
}
- (NSString *) matchedTextWithSource: (NSString *) sourceText {
NSString *returnString;
if (textOfLabel == matchText) {
returnString = [[NSString alloc]initWithString: [sourceText substringWithRange: [self range]]];
[returnString autorelease];
return returnString;
} else {
return [self theText];
}
}
#pragma mark-
#pragma mark Other methods
- (NSString *) displayInOutlineWithSource: (NSString *) sourceText {
// Use when object is to be called from a NSOutlineView-datasource.
NSString *returnString;
if (textOfLabel == matchText) {
returnString = [[NSString alloc] initWithString: NSLocalizedString(@"Matched text", nil)];
} else {
returnString = [[NSString alloc] initWithString: NSLocalizedString(@"Replacement text", nil)];
}
[returnString autorelease];
return returnString;
}
- (int) numberOfChildrenShowingReplacements: (BOOL) showReplacements {
// Use when object is to be called from a NSOutlineView-datasource.
return 1;
}
- (id) child: (int) index {
return containedText;
}
- (NSRange) range {
return [containedText range];
}
#pragma mark-
#pragma mark Cleaning up
- (void) dealloc {
[containedText release];
[super dealloc];
}
@end