forked from erkyrath/Inform7-IDE-Mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFRestrictedString.m
64 lines (46 loc) · 1.28 KB
/
IFRestrictedString.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
//
// IFRestrictedString.m
// Inform-xc2
//
// Created by Andrew Hunter on 05/01/2008.
// Copyright 2008 Andrew Hunter. All rights reserved.
//
#import "IFRestrictedString.h"
@implementation IFRestrictedString
// = Initialisation =
- (id) initWithString: (NSString*) source {
self = [self init];
if (self) {
sourceString = [source retain];
restriction = NSMakeRange(0, [sourceString length]);
}
return self;
}
- (void) dealloc {
[sourceString autorelease];
[super dealloc];
}
- (void) setRestriction: (NSRange) newRestriction {
restriction = newRestriction;
}
// = Mandatory NSString methods =
- (unsigned int) length {
return restriction.length;
}
- (unichar)characterAtIndex: (unsigned int) index {
return [sourceString characterAtIndex: index + restriction.location];
}
// = Extra NSString methods =
- (void) getCharacters: (unichar*) buffer {
[sourceString getCharacters: buffer
range: restriction];
}
- (void) getCharacters: (unichar*) buffer
range: (NSRange) range {
[sourceString getCharacters: buffer
range: NSMakeRange(range.location + restriction.location, range.length)];
}
- (NSString*) substringWithRange: (NSRange)range {
return [sourceString substringWithRange: NSMakeRange(range.location + restriction.location, range.length)];
}
@end